Search in sources :

Example 11 with Employee

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

Example 12 with Employee

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());
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IMap(com.hazelcast.map.IMap) PortableEmployee(com.hazelcast.query.SampleTestObjects.PortableEmployee) Employee(com.hazelcast.query.SampleTestObjects.Employee) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Collection(java.util.Collection) 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)

Example 13 with Employee

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);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) 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)

Example 14 with Employee

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;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) Config(com.hazelcast.config.Config) ArrayList(java.util.ArrayList) SampleTestObjects(com.hazelcast.query.SampleTestObjects) Timestamp(java.sql.Timestamp) Employee(com.hazelcast.query.SampleTestObjects.Employee)

Example 15 with Employee

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);
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee) QuickTest(com.hazelcast.test.annotation.QuickTest) DateHelperTest(com.hazelcast.query.impl.DateHelperTest) 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