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();
}
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]);
}
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));
}
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());
}
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);
}
}
Aggregations