try {
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap("default");
assertEquals(0, txMap.keySet(new SqlPredicate("age <= 10")).size());
//put
txMap.put(2, employee2);
Set keys = txMap.keySet(new SqlPredicate("age <= 10"));
Iterator iterator = keys.iterator();
assertEquals(1, keys.size());
while (iterator.hasNext()) {
assertEquals(2, ((Integer) iterator.next()).intValue());
}
txMap.put(3, employee3);
txMap.put(4, employee4);
keys = txMap.keySet(new SqlPredicate("age <= 10"));
assertEquals(3, keys.size());
// force rollback.
throw new DummyUncheckedHazelcastTestException();
}
});
} catch (Exception e) {
if (!(e instanceof DummyUncheckedHazelcastTestException)) {
throw new RuntimeException(e);
}
}
assertEquals(1, map.size());
assertEquals(1, map.keySet().size());
assertEquals(0, map.keySet(new SqlPredicate("age <= 10")).size());
h1.shutdown();
h2.shutdown();
}