use of com.hazelcast.query.SampleObjects.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.SampleObjects.Employee in project hazelcast by hazelcast.
the class IndexesTest method testIndex.
@Test
public void testIndex() throws Exception {
Indexes indexes = new Indexes(serializationService, Extractors.empty());
indexes.addOrGetIndex("name", false);
indexes.addOrGetIndex("age", true);
indexes.addOrGetIndex("salary", true);
for (int i = 0; i < 2000; i++) {
Employee employee = new Employee(i + "Name", i % 80, (i % 2 == 0), 100 + (i % 100));
indexes.saveEntryIndex(new QueryEntry(serializationService, toData(i), employee, Extractors.empty()), null);
}
for (int i = 0; i < 10; i++) {
SqlPredicate predicate = new SqlPredicate("salary=161 and age >20 and age <23");
Set<QueryableEntry> results = new HashSet<QueryableEntry>(indexes.query(predicate));
assertEquals(5, results.size());
}
}
use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class SqlPredicateTest method testSql_withEnum.
@Test
public void testSql_withEnum() {
Employee value = createValue();
value.setState(SampleObjects.State.STATE2);
Employee nullNameValue = createValue(null);
assertSqlMatching("state == TestUtil.State.STATE2", value);
assertSqlMatching("state == " + SampleObjects.State.STATE2, value);
assertSqlNotMatching("state == TestUtil.State.STATE1", value);
assertSqlNotMatching("state == TestUtil.State.STATE1", nullNameValue);
assertSqlMatching("state == NULL", nullNameValue);
}
use of com.hazelcast.query.SampleObjects.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);
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(cfg);
try {
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, SampleObjects.State.STATE1));
}
EntryProcessor entryProcessor = new ChangeStateEntryProcessor();
EntryObject entryObject = new PredicateBuilder().getEntryObject();
Predicate predicate = entryObject.get("id").lessThan(5);
Map<Integer, Object> res = map.executeOnEntries(entryProcessor, predicate);
for (int i = 0; i < 5; i++) {
assertEquals(SampleObjects.State.STATE2, map.get(i).getState());
}
for (int i = 5; i < size; i++) {
assertEquals(SampleObjects.State.STATE1, map.get(i).getState());
}
for (int i = 0; i < 5; i++) {
assertEquals(((Employee) res.get(i)).getState(), SampleObjects.State.STATE2);
}
} finally {
instance1.shutdown();
instance2.shutdown();
}
}
use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class QueryIndexMigrationTest method testQueryDuringAndAfterMigration.
@Test(timeout = MINUTE)
public void testQueryDuringAndAfterMigration() throws Exception {
HazelcastInstance instance = nodeFactory.newHazelcastInstance();
int count = 500;
IMap<String, Employee> map = instance.getMap("employees");
for (int i = 0; i < count; i++) {
map.put(String.valueOf(i), new Employee("joe" + i, i % 60, ((i & 1) == 1), (double) i));
}
nodeFactory.newInstances(new Config(), 3);
final IMap<String, Employee> employees = instance.getMap("employees");
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
Collection<Employee> values = employees.values(new SqlPredicate("active and name LIKE 'joe15%'"));
for (Employee employee : values) {
assertTrue(employee.isActive());
}
assertEquals(6, values.size());
}
}, 3);
}
Aggregations