use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testQueryAfterInitialLoad.
// issue 1404 "to be fixed by issue 1404"
@Test
public void testQueryAfterInitialLoad() {
final int size = 100;
String name = "default";
Config config = getConfig();
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setImplementation(new MapStoreAdapter<Integer, Employee>() {
@Override
public Map<Integer, Employee> loadAll(Collection<Integer> keys) {
Map<Integer, Employee> map = new HashMap<Integer, Employee>();
for (Integer key : keys) {
Employee emp = new Employee();
emp.setActive(true);
map.put(key, emp);
}
return map;
}
@Override
public Set<Integer> loadAllKeys() {
Set<Integer> set = new HashSet<Integer>();
for (int i = 0; i < size; i++) {
set.add(i);
}
return set;
}
});
config.getMapConfig(name).setMapStoreConfig(mapStoreConfig);
HazelcastInstance instance = createHazelcastInstance(config);
final IMap map = instance.getMap(name);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
Collection values = map.values(new SqlPredicate("active = true"));
assertEquals(size, values.size());
}
});
}
use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class WriteBehindWithEntryProcessorTest method testAllPartialUpdatesStored_whenInMemoryFormatIsObject.
@Test
public void testAllPartialUpdatesStored_whenInMemoryFormatIsObject() throws Exception {
CountDownLatch pauseStoreOp = new CountDownLatch(1);
JournalingMapStore<Integer, Employee> mapStore = new JournalingMapStore<Integer, Employee>(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.SampleObjects.Employee in project hazelcast by hazelcast.
the class WriteBehindWithEntryProcessorTest method getStoredSalaries.
private Double[] getStoredSalaries(JournalingMapStore<Integer, Employee> mapStore) {
List<Double> salaries = new ArrayList<Double>();
Iterator<Employee> iterator = mapStore.iterator();
while (iterator.hasNext()) {
Employee storedEmployee = iterator.next();
double salary = storedEmployee.getSalary();
salaries.add(salary);
}
return salaries.toArray(new Double[mapStore.queue.size()]);
}
use of com.hazelcast.query.SampleObjects.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("name", false);
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"));
}
use of com.hazelcast.query.SampleObjects.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(new SqlPredicate("age > 21")).size());
txMap.put(1, employeeAtAge23);
Collection coll = txMap.values(new SqlPredicate("age > 21"));
assertEquals(1, coll.size());
return true;
}
});
h1.shutdown();
h2.shutdown();
}
Aggregations