Search in sources :

Example 41 with Employee

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 42 with Employee

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);
}
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)

Example 43 with Employee

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"));
    }
}
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 44 with Employee

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());
}
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)

Example 45 with Employee

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());
    }
}
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) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap) 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