Search in sources :

Example 1 with Employee

use of com.hazelcast.query.SampleObjects.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("name", false);
    map.addIndex("age", true);
    map.addIndex("active", false);
    QueryBasicTest.doFunctionalSQLQueryTest(map);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) PortableEmployee(com.hazelcast.query.SampleObjects.PortableEmployee) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with Employee

use of com.hazelcast.query.SampleObjects.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("name", false);
    map.addIndex("age", true);
    map.addIndex("active", false);
    QueryBasicTest.doFunctionalQueryTest(map);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) PortableEmployee(com.hazelcast.query.SampleObjects.PortableEmployee) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with Employee

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

the class QueryAdvancedTest method testTwoNodesWithIndexes.

@Test
public void testTwoNodesWithIndexes() throws Exception {
    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("name", false);
    map.addIndex("city", false);
    map.addIndex("age", true);
    map.addIndex("active", false);
    for (int i = 0; i < 5000; i++) {
        Employee employee = new Employee(i, "name" + i % 100, "city" + (i % 100), i % 60, ((i & 1) == 1), (double) i);
        map.put(String.valueOf(i), employee);
    }
    assertEquals(2, instance1.getCluster().getMembers().size());
    assertEquals(2, instance2.getCluster().getMembers().size());
    map = instance2.getMap("employees");
    map.addIndex("name", false);
    map.addIndex("city", false);
    map.addIndex("age", true);
    map.addIndex("active", false);
    Collection<Employee> entries = map.values(new SqlPredicate("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(new SqlPredicate("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(new SqlPredicate("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) Employee(com.hazelcast.query.SampleObjects.Employee) PortableEmployee(com.hazelcast.query.SampleObjects.PortableEmployee) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with Employee

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

the class NearCacheTest method testAfterExecuteOnEntriesNearCacheIsInvalidated.

@Test
public void testAfterExecuteOnEntriesNearCacheIsInvalidated() {
    int mapSize = 10;
    String mapName = randomMapName();
    Config config = createNearCachedMapConfig(mapName);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, Employee> map = instance.getMap(mapName);
    for (int i = 0; i < mapSize; i++) {
        map.put(i, new Employee(i, "", 0, true, 0D));
    }
    populateNearCache(map, mapSize);
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("salary").equal(0);
    map.executeOnEntries(new AbstractEntryProcessor<Integer, Employee>() {

        @Override
        public Object process(Map.Entry<Integer, Employee> entry) {
            Employee employee = entry.getValue();
            double currentSalary = employee.getSalary();
            double newSalary = currentSalary + 10;
            employee.setSalary(newSalary);
            return newSalary;
        }
    }, predicate);
    assertEquals(0, getNearCacheStats(map).getOwnedEntryCount());
}
Also used : EntryObject(com.hazelcast.query.EntryObject) MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) Predicate(com.hazelcast.query.Predicate) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) PredicateBuilder(com.hazelcast.query.PredicateBuilder) EntryObject(com.hazelcast.query.EntryObject) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with Employee

use of com.hazelcast.query.SampleObjects.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("name", false);
    map.addIndex("age", true);
    map.addIndex("active", false);
    QueryBasicTest.doFunctionalQueryTest(map);
    assertEquals(101, map.size());
    instance2.getLifecycleService().shutdown();
    assertEquals(101, map.size());
    Set<Map.Entry<String, Employee>> entries = map.entrySet(new SqlPredicate("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) Employee(com.hazelcast.query.SampleObjects.Employee) PortableEmployee(com.hazelcast.query.SampleObjects.PortableEmployee) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Employee (com.hazelcast.query.SampleObjects.Employee)49 Test (org.junit.Test)41 QuickTest (com.hazelcast.test.annotation.QuickTest)38 HazelcastInstance (com.hazelcast.core.HazelcastInstance)36 ParallelTest (com.hazelcast.test.annotation.ParallelTest)35 Config (com.hazelcast.config.Config)28 SqlPredicate (com.hazelcast.query.SqlPredicate)23 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)21 MapIndexConfig (com.hazelcast.config.MapIndexConfig)18 MapStoreConfig (com.hazelcast.config.MapStoreConfig)17 PortableEmployee (com.hazelcast.query.SampleObjects.PortableEmployee)14 IMap (com.hazelcast.core.IMap)11 MapConfig (com.hazelcast.config.MapConfig)10 Collection (java.util.Collection)8 Map (java.util.Map)8 EntryObject (com.hazelcast.query.EntryObject)6 Predicate (com.hazelcast.query.Predicate)6 PredicateBuilder (com.hazelcast.query.PredicateBuilder)6 HashMap (java.util.HashMap)6 TransactionalMap (com.hazelcast.core.TransactionalMap)5