use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionLockingTest method testTxnReplace_whenReplaceFails_keyShouldRemainUnlocked.
@Test
public void testTxnReplace_whenReplaceFails_keyShouldRemainUnlocked() throws InterruptedException {
HazelcastInstance hazelcastInstance = createHazelcastInstance(getConfig());
IMap<String, Object> map = hazelcastInstance.getMap(mapName);
hazelcastInstance.executeTransaction(new TransactionalTask<Object>() {
@Override
public Object execute(TransactionalTaskContext transactionContext) throws TransactionException {
TransactionalMap<String, Object> transactionalMap = transactionContext.getMap(mapName);
transactionalMap.replace(key, value);
return null;
}
});
assertFalse("Key remains locked!", map.isLocked(key));
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionLockingTest method testTxnPutIfAbsent_whenPutFails_keyShouldRemainLocked_whenExplicitlyLocked.
@Test
public void testTxnPutIfAbsent_whenPutFails_keyShouldRemainLocked_whenExplicitlyLocked() throws InterruptedException {
final HazelcastInstance hazelcastInstance = createHazelcastInstance(getConfig());
final IMap<String, Object> map = hazelcastInstance.getMap(mapName);
map.put(key, value);
hazelcastInstance.executeTransaction(new TransactionalTask<Object>() {
@Override
public Object execute(TransactionalTaskContext transactionContext) throws TransactionException {
TransactionalMap<String, Object> transactionalMap = transactionContext.getMap(mapName);
transactionalMap.getForUpdate(key);
transactionalMap.putIfAbsent(key, "t");
assertTrue("Key remains unlocked!", map.isLocked(key));
return null;
}
});
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionLockingTest method testTxnReplace_whenReplaceIfSameFails_keyShouldRemainUnlocked.
@Test
public void testTxnReplace_whenReplaceIfSameFails_keyShouldRemainUnlocked() throws InterruptedException {
HazelcastInstance hazelcastInstance = createHazelcastInstance(getConfig());
IMap<String, Object> map = hazelcastInstance.getMap(mapName);
map.put(key, value);
hazelcastInstance.executeTransaction(new TransactionalTask<Object>() {
@Override
public Object execute(TransactionalTaskContext transactionContext) throws TransactionException {
TransactionalMap<String, Object> transactionalMap = transactionContext.getMap(mapName);
transactionalMap.replace(key, value + "other", value);
return null;
}
});
assertFalse("Key remains locked!", map.isLocked(key));
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionLockingTest method testTxnReplace_whenReplaceFails_keyShouldRemainUnlockedDuringTransaction.
@Test
public void testTxnReplace_whenReplaceFails_keyShouldRemainUnlockedDuringTransaction() throws InterruptedException {
final HazelcastInstance hazelcastInstance = createHazelcastInstance(getConfig());
final IMap<String, Object> map = hazelcastInstance.getMap(mapName);
hazelcastInstance.executeTransaction(new TransactionalTask<Object>() {
@Override
public Object execute(TransactionalTaskContext transactionContext) throws TransactionException {
TransactionalMap<String, Object> transactionalMap = transactionContext.getMap(mapName);
transactionalMap.replace(key, value);
assertFalse("Key remains locked!", map.isLocked(key));
return null;
}
});
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionLockingTest method testTxnRemoveIfSame_whenRemoveFails_keyShouldRemainUnlockedDuringTransaction.
@Test
public void testTxnRemoveIfSame_whenRemoveFails_keyShouldRemainUnlockedDuringTransaction() throws InterruptedException {
final HazelcastInstance hazelcastInstance = createHazelcastInstance(getConfig());
final IMap<String, Object> map = hazelcastInstance.getMap(mapName);
map.put(key, value);
hazelcastInstance.executeTransaction(new TransactionalTask<Object>() {
@Override
public Object execute(TransactionalTaskContext transactionContext) throws TransactionException {
TransactionalMap<String, Object> transactionalMap = transactionContext.getMap(mapName);
transactionalMap.remove(key, "");
assertFalse("Key remains locked!", map.isLocked(key));
return null;
}
});
}
Aggregations