Search in sources :

Example 36 with Employee

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

the class QueryBasicTest method testInvalidSqlPredicate.

@Test(timeout = 1000 * 90)
public void testInvalidSqlPredicate() {
    Config cfg = getConfig();
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(1);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(cfg);
    IMap<Integer, Employee> map = instance.getMap("employee");
    map.put(1, new Employee("e", 1, false, 0));
    map.put(2, new Employee("e2", 1, false, 0));
    try {
        map.values(Predicates.sql("invalid_sql"));
        fail("Should fail because of invalid SQL!");
    } catch (RuntimeException e) {
        assertContains(e.getMessage(), "There is no suitable accessor for 'invalid_sql'");
    }
    try {
        map.values(Predicates.sql("invalid sql"));
        fail("Should fail because of invalid SQL!");
    } catch (RuntimeException e) {
        assertContains(e.getMessage(), "Invalid SQL: [invalid sql]");
    }
    try {
        map.values(Predicates.sql("invalid and sql"));
        fail("Should fail because of invalid SQL!");
    } catch (RuntimeException e) {
        assertContains(e.getMessage(), "There is no suitable accessor for 'invalid'");
    }
    try {
        map.values(Predicates.sql("invalid sql and"));
        fail("Should fail because of invalid SQL!");
    } catch (RuntimeException e) {
        assertContains(e.getMessage(), "There is no suitable accessor for 'invalid'");
    }
    try {
        map.values(Predicates.sql(""));
        fail("Should fail because of invalid SQL!");
    } catch (RuntimeException e) {
        assertContains(e.getMessage(), "Invalid SQL: []");
    }
    assertEquals(2, map.values(Predicates.sql("age=1 and name like 'e%'")).size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 37 with Employee

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

the class QueryBasicTest method testMultipleOrPredicatesIssue885WithoutIndex.

@Test(timeout = 1000 * 90)
public void testMultipleOrPredicatesIssue885WithoutIndex() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    factory.newHazelcastInstance(getConfig());
    IMap<Integer, Employee> map = instance.getMap("default");
    testMultipleOrPredicates(map);
}
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 38 with Employee

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

the class QueryBasicTest method testMultipleOrPredicatesIssue885WithIndex.

@Test(timeout = 1000 * 90)
public void testMultipleOrPredicatesIssue885WithIndex() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    factory.newHazelcastInstance(getConfig());
    IMap<Integer, Employee> map = instance.getMap("default");
    map.addIndex(IndexType.SORTED, "name");
    testMultipleOrPredicates(map);
}
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 39 with Employee

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

the class QueryBasicTest method doFunctionalSQLQueryTest.

public static void doFunctionalSQLQueryTest(IMap<String, Employee> map) {
    map.put("1", new Employee("joe", 33, false, 14.56));
    map.put("2", new Employee("ali", 23, true, 15.00));
    for (int i = 3; i < 103; i++) {
        map.put(String.valueOf(i), new Employee("name" + i, i % 60, ((i & 1) == 1), i));
    }
    Set<Map.Entry<String, Employee>> entries = map.entrySet();
    assertEquals(102, entries.size());
    int entryCount = 0;
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertNotNull(employee);
        entryCount++;
    }
    assertEquals(102, entryCount);
    entries = map.entrySet(Predicates.sql("active=true and age=23"));
    assertEquals(3, entries.size());
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertEquals(employee.getAge(), 23);
        assertTrue(employee.isActive());
    }
    map.remove("2");
    entries = map.entrySet(Predicates.sql("active=true and age=23"));
    assertEquals(2, entries.size());
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertEquals(employee.getAge(), 23);
        assertTrue(employee.isActive());
    }
    entries = map.entrySet(Predicates.sql("age!=33"));
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertTrue(employee.getAge() != 33);
    }
    entries = map.entrySet(Predicates.sql("active!=false"));
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertTrue(employee.isActive());
    }
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee) Map(java.util.Map) IMap(com.hazelcast.map.IMap)

Example 40 with Employee

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

the class QueryIndexTest method testOneIndexedFieldsWithTwoCriteriaField.

@Test(timeout = 1000 * 60)
public void testOneIndexedFieldsWithTwoCriteriaField() {
    HazelcastInstance h1 = createTestHazelcastInstance();
    IMap<String, Employee> map = h1.getMap("employees");
    map.addIndex(IndexType.HASH, "name");
    map.put("1", new Employee(1L, "joe", 30, true, 100D));
    EntryObject e = Predicates.newPredicateBuilder().getEntryObject();
    PredicateBuilder a = e.get("name").equal("joe");
    Predicate b = e.get("age").equal("30");
    Collection<Employee> actual = map.values(a.and(b));
    assertEquals(1, actual.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) Predicate(com.hazelcast.query.Predicate) 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