Search in sources :

Example 21 with Employee

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

the class MapTransactionTest method testValues_WithPredicates_notContains_oldValues.

@Test
public void testValues_WithPredicates_notContains_oldValues() throws TransactionException {
    Config config = getConfig();
    final String mapName = "testValuesWithPredicate_notContains_oldValues";
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance h1 = factory.newHazelcastInstance(config);
    final HazelcastInstance h2 = factory.newHazelcastInstance(config);
    final IMap<Integer, Employee> map = h1.getMap(mapName);
    final Employee employeeAtAge22 = new Employee("emin", 22, true, 10D);
    final Employee employeeAtAge23 = new Employee("emin", 23, true, 10D);
    map.put(1, employeeAtAge22);
    h1.executeTransaction(options, new TransactionalTask<Boolean>() {

        public Boolean execute(TransactionalTaskContext context) throws TransactionException {
            TransactionalMap<Object, Object> txMap = context.getMap(mapName);
            assertEquals(1, txMap.values(Predicates.sql("age > 21")).size());
            txMap.put(1, employeeAtAge23);
            Collection coll = txMap.values(Predicates.sql("age > 21"));
            assertEquals(1, coll.size());
            return true;
        }
    });
    h1.shutdown();
    h2.shutdown();
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) TransactionException(com.hazelcast.transaction.TransactionException) Collection(java.util.Collection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 22 with Employee

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

the class MapStoreWriteThroughTest method testOneMemberWriteThrough.

@Test(timeout = 120000)
public void testOneMemberWriteThrough() throws Exception {
    TestMapStore testMapStore = new TestMapStore(1, 1, 1);
    testMapStore.setLoadAllKeys(false);
    Config config = newConfig(testMapStore, 0);
    HazelcastInstance instance = createHazelcastInstance(config);
    Employee employee = new Employee("joe", 25, true, 100.00);
    Employee newEmployee = new Employee("ali", 26, true, 1000);
    testMapStore.insert("1", employee);
    testMapStore.insert("2", employee);
    testMapStore.insert("3", employee);
    testMapStore.insert("4", employee);
    testMapStore.insert("5", employee);
    testMapStore.insert("6", employee);
    testMapStore.insert("7", employee);
    IMap<String, Employee> map = instance.getMap("default");
    map.addIndex(IndexType.HASH, "name");
    assertEquals(0, map.size());
    assertEquals(employee, map.get("1"));
    assertEquals(employee, testMapStore.getStore().get("1"));
    assertEquals(1, map.size());
    assertEquals(employee, map.put("2", newEmployee));
    assertEquals(newEmployee, testMapStore.getStore().get("2"));
    assertEquals(2, map.size());
    map.remove("1");
    map.put("1", employee, 1, TimeUnit.SECONDS);
    map.put("1", employee);
    Thread.sleep(2000);
    assertEquals(employee, testMapStore.getStore().get("1"));
    assertEquals(employee, map.get("1"));
    map.evict("2");
    assertEquals(newEmployee, map.get("2"));
    assertEquals(employee, map.get("3"));
    assertEquals(employee, map.put("3", newEmployee));
    assertEquals(newEmployee, map.get("3"));
    assertEquals(employee, map.remove("4"));
    assertEquals(employee, map.get("5"));
    assertEquals(employee, map.remove("5"));
    assertEquals(employee, map.putIfAbsent("6", newEmployee));
    assertEquals(employee, map.get("6"));
    assertEquals(employee, testMapStore.getStore().get("6"));
    assertTrue(map.containsKey("7"));
    assertEquals(employee, map.get("7"));
    assertNull(map.get("8"));
    assertFalse(map.containsKey("8"));
    assertNull(map.putIfAbsent("8", employee));
    assertEquals(employee, map.get("8"));
    assertEquals(employee, testMapStore.getStore().get("8"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with Employee

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

the class IndexesTest method testIndex.

@Test
public void testIndex() {
    Indexes indexes = Indexes.newBuilder(serializationService, copyBehavior, DEFAULT_IN_MEMORY_FORMAT).build();
    indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "name"));
    indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.SORTED, "age"));
    indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.SORTED, "salary"));
    for (int i = 0; i < 2000; i++) {
        Employee employee = new Employee(i + "Name", i % 80, (i % 2 == 0), 100 + (i % 100));
        indexes.putEntry(new QueryEntry(serializationService, toData(i), employee, newExtractor()), null, Index.OperationSource.USER);
    }
    for (int i = 0; i < 10; i++) {
        SqlPredicate predicate = new SqlPredicate("salary=161 and age >20 and age <23");
        assertEquals(5, size(indexes.query(predicate, SKIP_PARTITIONS_COUNT_CHECK)));
    }
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee) SqlPredicate(com.hazelcast.query.impl.predicates.SqlPredicate) IndexMatchHint(com.hazelcast.query.impl.QueryContext.IndexMatchHint) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with Employee

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

the class WriteBehindWithEntryProcessorTest method updateSalary.

private void updateSalary(IMap<Integer, Employee> map, int key, final double value) {
    map.executeOnKey(key, entry -> {
        Employee employee = entry.getValue();
        if (employee == null) {
            employee = new Employee();
        }
        employee.setSalary(value);
        entry.setValue(employee);
        return null;
    });
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee)

Example 25 with Employee

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

the class QueryIndexingTest method newEmployees.

private static Map<Integer, Employee> newEmployees(int employeeCount) {
    Map<Integer, Employee> employees = new HashMap<>();
    for (int i = 0; i < employeeCount; i++) {
        Employee val;
        if (i % 2 == 0) {
            val = new Employee(i, null, null, 0, true, i);
        } else {
            val = new Employee(i, "name" + i, "city" + i, 0, true, i);
        }
        Employee spy = MockUtil.serializableSpy(Employee.class, val);
        employees.put(i, spy);
    }
    return employees;
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee) HashMap(java.util.HashMap)

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