use of com.hazelcast.transaction.TransactionException 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.TransactionException 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.TransactionException 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.TransactionException 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());
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class TransactionsWithWriteBehind_whenNoCoalescingQueueIsFullTest method name.
@Test
public void name() {
String mapName = "map";
Config config = getConfig(mapName, 50);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance node1 = factory.newHazelcastInstance(config);
HazelcastInstance node2 = factory.newHazelcastInstance(config);
for (int ii = 0; ii < 100; ii++) {
TransactionContext context = newTransactionContext(node1, TWO_PHASE);
context.beginTransaction();
TransactionalMap map = context.getMap("map");
for (int i = 0; i < 51; i++) {
map.put("item-" + i, "value");
}
try {
context.commitTransaction();
} catch (TransactionException e) {
context.rollbackTransaction();
}
}
HazelcastInstance node3 = factory.newHazelcastInstance(config);
assertTrueEventually(() -> {
Collection<HazelcastInstance> instances = factory.getAllHazelcastInstances();
for (HazelcastInstance node : instances) {
assertWriteBehindQueuesEmpty(mapName, Collections.singletonList(node));
assertEquals(0, getNodeWideUsedCapacity(node));
assertEquals(0, getTotalNumOfTxnReservedCapacity(mapName, node));
}
}, 30);
}
Aggregations