use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testRemove_whenNullKey.
@Test(expected = NullPointerException.class)
public void testRemove_whenNullKey() throws TransactionException {
final HazelcastInstance hz = createHazelcastInstance();
hz.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
TransactionalMap<Object, Object> txMap = context.getMap("default");
txMap.remove(null);
return true;
}
});
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testReplace_whenNullNewValue.
@Test(expected = NullPointerException.class)
public void testReplace_whenNullNewValue() throws TransactionException {
final HazelcastInstance hz = createHazelcastInstance();
hz.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
TransactionalMap<Object, Object> txMap = context.getMap("default");
txMap.replace("key", "oldvalue", null);
return true;
}
});
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method tesPutIfAbsent_whenNullKey.
// ========================= putIfAbsent =====================
@Test(expected = NullPointerException.class)
public void tesPutIfAbsent_whenNullKey() throws TransactionException {
final HazelcastInstance hz = createHazelcastInstance();
hz.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
TransactionalMap<Object, Object> txMap = context.getMap("default");
txMap.putIfAbsent(null, "value");
return true;
}
});
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testTxnReplace2.
@Test
public void testTxnReplace2() throws TransactionException {
Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
final IMap map2 = h2.getMap("default");
map2.put("1", "value2");
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap("default");
assertEquals("value2", txMap.replace("1", "value3"));
assertEquals("value3", txMap.get("1"));
assertNull(map2.get("2"));
return true;
}
});
assertTrue(b);
IMap map1 = h1.getMap("default");
assertEquals("value3", map1.get("1"));
assertEquals("value3", map2.get("1"));
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class TransactionsWithWriteBehind_whenNoCoalescingQueueIsFullTest method rollback_successful_when_prepare_step_throws_exception_when_two_phase.
@Test
public void rollback_successful_when_prepare_step_throws_exception_when_two_phase() {
String mapName = "map";
String queueName = "queue";
long maxWbqCapacity = 100;
Config config = getConfig(mapName, maxWbqCapacity);
HazelcastInstance node = createHazelcastInstance(config);
TransactionContext context = newTransactionContext(node, TWO_PHASE);
try {
context.beginTransaction();
TransactionalQueue queue = context.getQueue(queueName);
queue.offer(1);
queue.offer(2);
queue.offer(3);
TransactionalMap map = context.getMap(mapName);
for (int i = 0; i < 1000; i++) {
map.put("item-" + i, "value");
}
context.commitTransaction();
} catch (TransactionException e) {
context.rollbackTransaction();
}
assertEquals(0, node.getQueue(queueName).size());
assertEquals(0, node.getMap(mapName).size());
}
Aggregations