use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testRemove.
@Test
public void testRemove() throws TransactionException {
Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
final IMap map1 = h1.getMap("default");
final IMap map2 = h2.getMap("default");
map2.put("1", "1");
map2.put("2", "2");
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap("default");
txMap.put("3", "3");
map2.put("4", "4");
assertEquals("1", txMap.remove("1"));
assertEquals("2", map1.remove("2"));
assertEquals("1", map1.get("1"));
assertEquals(null, txMap.get("1"));
assertEquals(null, txMap.remove("2"));
assertEquals(2, txMap.size());
return true;
}
});
assertTrue(b);
assertEquals(null, map1.get("1"));
assertEquals(null, map2.get("1"));
assertEquals(null, map1.get("2"));
assertEquals(null, map2.get("2"));
assertEquals("3", map1.get("3"));
assertEquals("3", map2.get("3"));
assertEquals("4", map1.get("4"));
assertEquals("4", map2.get("4"));
}
use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.
the class TransactionalMapSetMessageTask method innerCall.
@Override
protected Object innerCall() throws Exception {
final TransactionContext context = getEndpoint().getTransactionContext(parameters.txnId);
final TransactionalMap map = context.getMap(parameters.name);
map.set(parameters.key, parameters.value);
return null;
}
use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.
the class TransactionalMapSizeMessageTask method innerCall.
@Override
protected Object innerCall() throws Exception {
final TransactionContext context = getEndpoint().getTransactionContext(parameters.txnId);
final TransactionalMap map = context.getMap(parameters.name);
return map.size();
}
use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.
the class TransactionalMapValuesMessageTask method innerCall.
@Override
protected Object innerCall() throws Exception {
final TransactionContext context = getEndpoint().getTransactionContext(parameters.txnId);
final TransactionalMap map = context.getMap(parameters.name);
Collection values = map.values();
List<Data> list = new ArrayList<Data>(values.size());
for (Object o : values) {
list.add(serializationService.toData(o));
}
return list;
}
use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.
the class TransactionalMapValuesWithPredicateMessageTask method innerCall.
@Override
protected Object innerCall() throws Exception {
final TransactionContext context = getEndpoint().getTransactionContext(parameters.txnId);
final TransactionalMap map = context.getMap(parameters.name);
Predicate predicate = serializationService.toObject(parameters.predicate);
Collection values = map.values(predicate);
List<Data> list = new ArrayList<Data>(values.size());
for (Object o : values) {
list.add(serializationService.toData(o));
}
return list;
}
Aggregations