Search in sources :

Example 16 with Employee

use of com.hazelcast.query.SampleTestObjects.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.transaction.TransactionalMap) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) IMap(com.hazelcast.map.IMap) 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 17 with Employee

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

the class WriteBehindWithEntryProcessorTest method getStoredSalaries.

private Double[] getStoredSalaries(JournalingMapStore<Integer, Employee> mapStore) {
    List<Double> salaries = new ArrayList<>();
    Iterator<Employee> iterator = mapStore.iterator();
    while (iterator.hasNext()) {
        Employee storedEmployee = iterator.next();
        double salary = storedEmployee.getSalary();
        salaries.add(salary);
    }
    return salaries.toArray(new Double[0]);
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee) ArrayList(java.util.ArrayList)

Example 18 with Employee

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

the class WriteBehindWithEntryProcessorTest method testAllPartialUpdatesStored_whenInMemoryFormatIsObject.

@Test
public void testAllPartialUpdatesStored_whenInMemoryFormatIsObject() {
    CountDownLatch pauseStoreOp = new CountDownLatch(1);
    JournalingMapStore<Integer, Employee> mapStore = new JournalingMapStore<>(pauseStoreOp);
    IMap<Integer, Employee> map = TestMapUsingMapStoreBuilder.<Integer, Employee>create().withMapStore(mapStore).withNodeFactory(createHazelcastInstanceFactory(1)).withWriteDelaySeconds(1).withWriteCoalescing(false).withInMemoryFormat(InMemoryFormat.OBJECT).build();
    Double[] salaries = { 73D, 111D, -23D, 99D, 12D, 77D, 33D };
    for (Double salary : salaries) {
        updateSalary(map, 1, salary);
    }
    pauseStoreOp.countDown();
    assertStoreOperationsCompleted(salaries.length, mapStore);
    assertArrayEquals("Map store should contain all partial updates on the object", salaries, getStoredSalaries(mapStore));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Employee(com.hazelcast.query.SampleTestObjects.Employee) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) MapStoreTest(com.hazelcast.map.impl.mapstore.MapStoreTest) Test(org.junit.Test)

Example 19 with Employee

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

the class NearCacheTest method testAfterExecuteOnEntriesNearCacheIsInvalidated.

@Test
public void testAfterExecuteOnEntriesNearCacheIsInvalidated() {
    int mapSize = 10;
    String mapName = randomMapName();
    Config config = createNearCachedMapConfig(mapName);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, Employee> map = instance.getMap(mapName);
    for (int i = 0; i < mapSize; i++) {
        map.put(i, new Employee(i, "", 0, true, 0D));
    }
    populateNearCache(map, mapSize);
    EntryObject e = Predicates.newPredicateBuilder().getEntryObject();
    Predicate predicate = e.get("salary").equal(0);
    map.executeOnEntries(entry -> {
        Employee employee = entry.getValue();
        double currentSalary = employee.getSalary();
        double newSalary = currentSalary + 10;
        employee.setSalary(newSalary);
        return newSalary;
    }, predicate);
    assertEquals(0, getNearCacheStats(map).getOwnedEntryCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with Employee

use of com.hazelcast.query.SampleTestObjects.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);
    nodeFactory.newHazelcastInstance(cfg);
    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, SampleTestObjects.State.STATE1));
    }
    ChangeStateEntryProcessor entryProcessor = new ChangeStateEntryProcessor();
    EntryObject entryObject = Predicates.newPredicateBuilder().getEntryObject();
    Predicate<Integer, Employee> predicate = entryObject.get("id").lessThan(5);
    Map<Integer, Employee> res = map.executeOnEntries(entryProcessor, predicate);
    for (int i = 0; i < 5; i++) {
        assertEquals(SampleTestObjects.State.STATE2, map.get(i).getState());
    }
    for (int i = 5; i < size; i++) {
        assertEquals(SampleTestObjects.State.STATE1, map.get(i).getState());
    }
    for (int i = 0; i < 5; i++) {
        assertEquals(res.get(i).getState(), SampleTestObjects.State.STATE2);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) MapConfig(com.hazelcast.config.MapConfig) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) 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