Search in sources :

Example 11 with Employee

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

the class MapTransactionTest method testValues_resultSetContainsUpdatedEntry.

@Test
public void testValues_resultSetContainsUpdatedEntry() throws TransactionException {
    final int nodeCount = 1;
    final String mapName = randomMapName();
    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<Integer, Employee> txMap = context.getMap(mapName);
            emp.setAge(30);
            txMap.put(1, emp);
            Collection<Employee> coll = txMap.values();
            assertEquals(1, coll.size());
            Employee employee = coll.iterator().next();
            assertEquals(30, employee.getAge());
            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) 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)

Example 12 with Employee

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

the class IndexesTest method testIndex.

@Test
public void testIndex() throws Exception {
    Indexes indexes = new Indexes(serializationService, Extractors.empty());
    indexes.addOrGetIndex("name", false);
    indexes.addOrGetIndex("age", true);
    indexes.addOrGetIndex("salary", true);
    for (int i = 0; i < 2000; i++) {
        Employee employee = new Employee(i + "Name", i % 80, (i % 2 == 0), 100 + (i % 100));
        indexes.saveEntryIndex(new QueryEntry(serializationService, toData(i), employee, Extractors.empty()), null);
    }
    for (int i = 0; i < 10; i++) {
        SqlPredicate predicate = new SqlPredicate("salary=161 and age >20 and age <23");
        Set<QueryableEntry> results = new HashSet<QueryableEntry>(indexes.query(predicate));
        assertEquals(5, results.size());
    }
}
Also used : Employee(com.hazelcast.query.SampleObjects.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) HashSet(java.util.HashSet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with Employee

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

the class SqlPredicateTest method testSql_withEnum.

@Test
public void testSql_withEnum() {
    Employee value = createValue();
    value.setState(SampleObjects.State.STATE2);
    Employee nullNameValue = createValue(null);
    assertSqlMatching("state == TestUtil.State.STATE2", value);
    assertSqlMatching("state == " + SampleObjects.State.STATE2, value);
    assertSqlNotMatching("state == TestUtil.State.STATE1", value);
    assertSqlNotMatching("state == TestUtil.State.STATE1", nullNameValue);
    assertSqlMatching("state == NULL", nullNameValue);
}
Also used : Employee(com.hazelcast.query.SampleObjects.Employee) QuickTest(com.hazelcast.test.annotation.QuickTest) DateHelperTest(com.hazelcast.query.impl.DateHelperTest) Test(org.junit.Test)

Example 14 with Employee

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

the class EntryProcessorTest method testMapEntryProcessorWithPredicate.

@Test
public void testMapEntryProcessorWithPredicate() {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    Config cfg = getConfig();
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(cfg);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(cfg);
    try {
        IMap<Integer, Employee> map = instance1.getMap(MAP_NAME);
        int size = 10;
        for (int i = 0; i < size; i++) {
            map.put(i, new Employee(i, "", 0, false, 0D, SampleObjects.State.STATE1));
        }
        EntryProcessor entryProcessor = new ChangeStateEntryProcessor();
        EntryObject entryObject = new PredicateBuilder().getEntryObject();
        Predicate predicate = entryObject.get("id").lessThan(5);
        Map<Integer, Object> res = map.executeOnEntries(entryProcessor, predicate);
        for (int i = 0; i < 5; i++) {
            assertEquals(SampleObjects.State.STATE2, map.get(i).getState());
        }
        for (int i = 5; i < size; i++) {
            assertEquals(SampleObjects.State.STATE1, map.get(i).getState());
        }
        for (int i = 0; i < 5; i++) {
            assertEquals(((Employee) res.get(i)).getState(), SampleObjects.State.STATE2);
        }
    } finally {
        instance1.shutdown();
        instance2.shutdown();
    }
}
Also used : EntryObject(com.hazelcast.query.EntryObject) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) Predicate(com.hazelcast.query.Predicate) IndexAwarePredicate(com.hazelcast.query.IndexAwarePredicate) SqlPredicate(com.hazelcast.query.SqlPredicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) PredicateBuilder(com.hazelcast.query.PredicateBuilder) EntryObject(com.hazelcast.query.EntryObject) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with Employee

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

the class QueryIndexMigrationTest method testQueryDuringAndAfterMigration.

@Test(timeout = MINUTE)
public void testQueryDuringAndAfterMigration() throws Exception {
    HazelcastInstance instance = nodeFactory.newHazelcastInstance();
    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(new 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());
            }
            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)

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