Search in sources :

Example 1 with Employee

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

the class QueryIndexMigrationTest method testQueryDuringAndAfterMigration.

@Test(timeout = MINUTE)
public void testQueryDuringAndAfterMigration() {
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(getTestConfig());
    int count = 500;
    IMap<String, Employee> map = instance.getMap("employees");
    for (int i = 0; i < count; i++) {
        map.put(String.valueOf(i), new Employee("joe" + i, i % 60, ((i & 1) == 1), (double) i));
    }
    nodeFactory.newInstances(getTestConfig(), 3);
    final IMap<String, Employee> employees = instance.getMap("employees");
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() throws Exception {
            Collection<Employee> values = employees.values(Predicates.sql("active and name LIKE 'joe15%'"));
            for (Employee employee : values) {
                assertTrue(employee.isActive());
            }
            assertEquals(6, values.size());
        }
    }, 3);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 2 with Employee

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

the class QueryIndexMigrationTest method testQueryDuringAndAfterMigrationWithIndex.

@Test
public void testQueryDuringAndAfterMigrationWithIndex() {
    Config config = getTestConfig();
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    IMap<String, Employee> map = instance.getMap("employees");
    map.addIndex(IndexType.HASH, "name");
    map.addIndex(IndexType.HASH, "active");
    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(Predicates.sql("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.SampleTestObjects.Employee) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 3 with Employee

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

the class QueryIndexMigrationTest method testQueryWithIndexesWhileMigrating.

@Test
public void testQueryWithIndexesWhileMigrating() {
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(getTestConfig());
    IMap<String, Employee> map = instance.getMap("employees");
    map.addIndex(IndexType.SORTED, "age");
    map.addIndex(IndexType.HASH, "active");
    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(Predicates.sql("active=true and age>44"));
    assertEquals(30, entries.size());
    nodeFactory.newInstances(getTestConfig(), 3);
    long startNow = Clock.currentTimeMillis();
    while ((Clock.currentTimeMillis() - startNow) < 10000) {
        entries = map.entrySet(Predicates.sql("active=true and age>44"));
        assertEquals(30, entries.size());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 4 with Employee

use of com.hazelcast.query.SampleTestObjects.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.SampleTestObjects.Employee)

Example 5 with Employee

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

the class QueryBasicTest method testMultipleOrPredicatesIssue885WithDoubleIndex.

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

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