Search in sources :

Example 21 with Employee

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

the class QueryBasicTest method testMultipleOrPredicatesIssue885WithDoubleIndex.

@Test(timeout = 1000 * 60)
public void testMultipleOrPredicatesIssue885WithDoubleIndex() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    factory.newHazelcastInstance(new Config());
    IMap<Integer, Employee> map = instance.getMap("default");
    map.addIndex("name", true);
    map.addIndex("city", true);
    testMultipleOrPredicates(map);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with Employee

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

the class QueryBasicTest method testMultipleOrPredicates.

private void testMultipleOrPredicates(IMap<Integer, Employee> map) {
    for (int i = 0; i < 10; i++) {
        map.put(i, new Employee(i, "name" + i, "city" + i, i, true, i));
    }
    Collection<Employee> values;
    values = map.values(new SqlPredicate("name = 'name1' OR name = 'name2' OR name LIKE 'name3'"));
    assertEquals(3, values.size());
    values = map.values(new SqlPredicate("name = 'name1' OR name LIKE 'name2%' OR name LIKE 'name3'"));
    assertEquals(3, values.size());
    values = map.values(new SqlPredicate("name = 'name1' OR name LIKE 'name2%' OR name == 'name3'"));
    assertEquals(3, values.size());
    values = map.values(new SqlPredicate("name LIKE '%name1' OR name LIKE 'name2%' OR name LIKE '%name3%'"));
    assertEquals(3, values.size());
    values = map.values(new SqlPredicate("name == 'name1' OR name == 'name2' OR name = 'name3'"));
    assertEquals(3, values.size());
    values = map.values(new SqlPredicate("name = 'name1' OR name = 'name2' OR city LIKE 'city3'"));
    assertEquals(3, values.size());
    values = map.values(new SqlPredicate("name = 'name1' OR name LIKE 'name2%' OR city LIKE 'city3'"));
    assertEquals(3, values.size());
    values = map.values(new SqlPredicate("name = 'name1' OR name LIKE 'name2%' OR city == 'city3'"));
    assertEquals(3, values.size());
    values = map.values(new SqlPredicate("name LIKE '%name1' OR name LIKE 'name2%' OR city LIKE '%city3%'"));
    assertEquals(3, values.size());
    values = map.values(new SqlPredicate("name == 'name1' OR name == 'name2' OR city = 'city3'"));
    assertEquals(3, values.size());
}
Also used : Employee(com.hazelcast.query.SampleObjects.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate)

Example 23 with Employee

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

the class QueryBasicTest method testWithDashInTheNameAndSqlPredicate.

@Test(timeout = 1000 * 60)
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(new SqlPredicate("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.SampleObjects.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) 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 24 with Employee

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

the class MapStoreTest method testIssue1115EnablingMapstoreMutatingValue.

@Test(timeout = 120000)
public void testIssue1115EnablingMapstoreMutatingValue() throws InterruptedException {
    Config config = getConfig();
    String mapName = "testIssue1115";
    MapStore mapStore = new ProcessingStore();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(mapStore);
    config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    nodeFactory.newHazelcastInstance(config);
    IMap<Integer, Employee> map = instance.getMap(mapName);
    Random random = new Random();
    // testing put with new object
    for (int i = 0; i < 10; i++) {
        Employee emp = new Employee();
        emp.setAge(random.nextInt(20) + 20);
        map.put(i, emp);
    }
    for (int i = 0; i < 10; i++) {
        Employee employee = map.get(i);
        assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
    // testing put with existing object
    for (int i = 0; i < 10; i++) {
        Employee emp = map.get(i);
        emp.setAge(random.nextInt(20) + 20);
        map.put(i, emp);
    }
    for (int i = 0; i < 10; i++) {
        Employee employee = map.get(i);
        assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
    // testing put with replace
    for (int i = 0; i < 10; i++) {
        Employee emp = map.get(i);
        emp.setAge(random.nextInt(20) + 20);
        map.replace(i, emp);
    }
    for (int i = 0; i < 10; i++) {
        Employee employee = map.get(i);
        assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
    // testing put with putIfAbsent
    for (int i = 10; i < 20; i++) {
        Employee emp = new Employee();
        emp.setAge(random.nextInt(20) + 20);
        map.putIfAbsent(i, emp);
    }
    for (int i = 10; i < 20; i++) {
        Employee employee = map.get(i);
        assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) Random(java.util.Random) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) MapStore(com.hazelcast.core.MapStore) PostProcessingMapStore(com.hazelcast.core.PostProcessingMapStore) 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 25 with Employee

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

the class MapTransactionTest method testValuesWithPredicate_removingExistentEntry.

@Test
public void testValuesWithPredicate_removingExistentEntry() throws TransactionException {
    final int nodeCount = 1;
    final String mapName = randomMapName("_testValuesWithPredicate_removingExistentEntry_");
    final Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance node = factory.newHazelcastInstance(config);
    final IMap map = node.getMap(mapName);
    final Employee emp = new Employee("name", 77, true, 10D);
    map.put(1, emp);
    node.executeTransaction(options, new TransactionalTask<Boolean>() {

        public Boolean execute(TransactionalTaskContext context) throws TransactionException {
            final TransactionalMap<Object, Object> txMap = context.getMap(mapName);
            txMap.remove(1);
            Collection<Object> coll = txMap.values(new SqlPredicate("age > 70 "));
            assertEquals(0, coll.size());
            return true;
        }
    });
    node.shutdown();
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) SqlPredicate(com.hazelcast.query.SqlPredicate) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) TransactionException(com.hazelcast.transaction.TransactionException) Collection(java.util.Collection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) 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