Search in sources :

Example 6 with Employee

use of com.hazelcast.query.SampleTestObjects.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(Predicates.sql("name = 'name1' OR name = 'name2' OR name LIKE 'name3'"));
    assertEquals(3, values.size());
    values = map.values(Predicates.sql("name = 'name1' OR name LIKE 'name2%' OR name LIKE 'name3'"));
    assertEquals(3, values.size());
    values = map.values(Predicates.sql("name = 'name1' OR name LIKE 'name2%' OR name == 'name3'"));
    assertEquals(3, values.size());
    values = map.values(Predicates.sql("name LIKE '%name1' OR name LIKE 'name2%' OR name LIKE '%name3%'"));
    assertEquals(3, values.size());
    values = map.values(Predicates.sql("name == 'name1' OR name == 'name2' OR name = 'name3'"));
    assertEquals(3, values.size());
    values = map.values(Predicates.sql("name = 'name1' OR name = 'name2' OR city LIKE 'city3'"));
    assertEquals(3, values.size());
    values = map.values(Predicates.sql("name = 'name1' OR name LIKE 'name2%' OR city LIKE 'city3'"));
    assertEquals(3, values.size());
    values = map.values(Predicates.sql("name = 'name1' OR name LIKE 'name2%' OR city == 'city3'"));
    assertEquals(3, values.size());
    values = map.values(Predicates.sql("name LIKE '%name1' OR name LIKE 'name2%' OR city LIKE '%city3%'"));
    assertEquals(3, values.size());
    values = map.values(Predicates.sql("name == 'name1' OR name == 'name2' OR city = 'city3'"));
    assertEquals(3, values.size());
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee)

Example 7 with Employee

use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.

the class QueryBasicTest method negativeDouble.

@Test(timeout = 1000 * 90)
public void negativeDouble() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Employee> map = instance.getMap("default");
    map.addIndex(IndexType.HASH, "salary");
    map.put("" + 4, new Employee(1, "default", 1, true, -70D));
    map.put("" + 3, new Employee(1, "default", 1, true, -60D));
    map.put("" + 1, new Employee(1, "default", 1, true, -10D));
    map.put("" + 2, new Employee(2, "default", 2, true, 10D));
    Predicate predicate = Predicates.sql("salary >= -60");
    Collection<Employee> values = map.values(predicate);
    assertEquals(3, values.size());
    predicate = Predicates.sql("salary between -20 and 20");
    values = map.values(predicate);
    assertEquals(2, values.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with Employee

use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.

the class QueryAdvancedTest method testTwoNodesWithIndexes.

@Test
public void testTwoNodesWithIndexes() {
    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.HASH, "city");
    map.addIndex(IndexType.SORTED, "age");
    map.addIndex(IndexType.HASH, "active");
    for (int i = 0; i < 5000; 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.HASH, "city");
    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(50, 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(50, 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(50, entries.size());
    for (Employee employee : entries) {
        assertTrue(employee.getName().startsWith("name3"));
        assertTrue(employee.getCity().startsWith("city3"));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PortableEmployee(com.hazelcast.query.SampleTestObjects.PortableEmployee) Employee(com.hazelcast.query.SampleTestObjects.Employee) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with Employee

use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.

the class QueryAdvancedTest method testTwoMembersWithIndexes.

@Test
public void testTwoMembersWithIndexes() {
    Config config = getConfig();
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    nodeFactory.newHazelcastInstance(config);
    IMap<String, Employee> map = instance.getMap("employees");
    map.addIndex(IndexType.HASH, "name");
    map.addIndex(IndexType.SORTED, "age");
    map.addIndex(IndexType.HASH, "active");
    QueryBasicTest.doFunctionalQueryTest(map);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PortableEmployee(com.hazelcast.query.SampleTestObjects.PortableEmployee) Employee(com.hazelcast.query.SampleTestObjects.Employee) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with Employee

use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.

the class QueryAdvancedTest method testOneMemberSQLWithIndex.

@Test
public void testOneMemberSQLWithIndex() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Employee> map = instance.getMap("employees");
    map.addIndex(IndexType.HASH, "name");
    map.addIndex(IndexType.SORTED, "age");
    map.addIndex(IndexType.HASH, "active");
    QueryBasicTest.doFunctionalSQLQueryTest(map);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PortableEmployee(com.hazelcast.query.SampleTestObjects.PortableEmployee) Employee(com.hazelcast.query.SampleTestObjects.Employee) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Employee (com.hazelcast.query.SampleTestObjects.Employee)52 Test (org.junit.Test)42 QuickTest (com.hazelcast.test.annotation.QuickTest)39 HazelcastInstance (com.hazelcast.core.HazelcastInstance)38 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)37 Config (com.hazelcast.config.Config)25 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)23 MapStoreConfig (com.hazelcast.config.MapStoreConfig)17 PortableEmployee (com.hazelcast.query.SampleTestObjects.PortableEmployee)14 IndexConfig (com.hazelcast.config.IndexConfig)13 IMap (com.hazelcast.map.IMap)11 MapConfig (com.hazelcast.config.MapConfig)8 Collection (java.util.Collection)8 Map (java.util.Map)8 Predicate (com.hazelcast.query.Predicate)7 EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)7 HashMap (java.util.HashMap)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 NightlyTest (com.hazelcast.test.annotation.NightlyTest)5 EvictionConfig (com.hazelcast.config.EvictionConfig)4