Search in sources :

Example 16 with Employee

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

the class QueryIndexMigrationTest method testQueryDuringAndAfterMigrationWithIndex.

@Test
public void testQueryDuringAndAfterMigrationWithIndex() throws Exception {
    Config config = new Config();
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    IMap<String, Employee> map = instance.getMap("employees");
    map.addIndex("name", false);
    map.addIndex("active", false);
    int size = 500;
    for (int i = 0; i < size; i++) {
        map.put(String.valueOf(i), new Employee("joe" + i, i % 60, ((i & 1) == 1), (double) i));
    }
    nodeFactory.newInstances(config, 3);
    final IMap<String, Employee> employees = instance.getMap("employees");
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() throws Exception {
            Collection<Employee> values = employees.values(new SqlPredicate("active and name LIKE 'joe15%'"));
            for (Employee employee : values) {
                assertTrue(employee.isActive() && employee.getName().startsWith("joe15"));
            }
            assertEquals(6, values.size());
        }
    }, 3);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) AssertTask(com.hazelcast.test.AssertTask) SqlPredicate(com.hazelcast.query.SqlPredicate) Collection(java.util.Collection) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with Employee

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

the class QueryIndexMigrationTest method testQueryWithIndexesWhileMigrating.

@Test
public void testQueryWithIndexesWhileMigrating() throws Exception {
    HazelcastInstance instance = nodeFactory.newHazelcastInstance();
    IMap<String, Employee> map = instance.getMap("employees");
    map.addIndex("age", true);
    map.addIndex("active", false);
    for (int i = 0; i < 500; i++) {
        map.put("e" + i, new Employee("name" + i, i % 50, ((i & 1) == 1), (double) i));
    }
    assertEquals(500, map.size());
    Set<Map.Entry<String, Employee>> entries = map.entrySet(new SqlPredicate("active=true and age>44"));
    assertEquals(30, entries.size());
    nodeFactory.newInstances(new Config(), 3);
    long startNow = Clock.currentTimeMillis();
    while ((Clock.currentTimeMillis() - startNow) < 10000) {
        entries = map.entrySet(new SqlPredicate("active=true and age>44"));
        assertEquals(30, entries.size());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with Employee

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

the class QueryIndexingTest method assertFieldsAreNull.

private static void assertFieldsAreNull(Collection<Employee> matchingEmployees) {
    for (Employee employee : matchingEmployees) {
        assertNull("city", employee.getCity());
        assertNull("name", employee.getName());
    }
}
Also used : Employee(com.hazelcast.query.SampleObjects.Employee)

Example 19 with Employee

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

the class QueryNullIndexingTest method queryIndexedDateFieldAsNullValue.

private List<Long> queryIndexedDateFieldAsNullValue(boolean ordered, Predicate pred) {
    HazelcastInstance instance = createHazelcastInstance();
    IMap<Integer, SampleObjects.Employee> map = instance.getMap("default");
    map.addIndex("date", ordered);
    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 (SampleObjects.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.SampleObjects.Employee) SampleObjects(com.hazelcast.query.SampleObjects) Employee(com.hazelcast.query.SampleObjects.Employee) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp)

Example 20 with Employee

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

the class QueryBasicTest method negativeDouble.

@Test(timeout = 1000 * 60)
public void negativeDouble() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Employee> map = instance.getMap("default");
    map.addIndex("salary", false);
    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 = new SqlPredicate("salary >= -60");
    Collection<Employee> values = map.values(predicate);
    assertEquals(3, values.size());
    predicate = new SqlPredicate("salary between -20 and 20");
    values = map.values(predicate);
    assertEquals(2, values.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) SqlPredicate(com.hazelcast.query.SqlPredicate) 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