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