use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionLockingTest method testTxnReplace_whenReplaceFails_keyShouldRemainLocked_whenExplicitlyLocked.
@Test
public void testTxnReplace_whenReplaceFails_keyShouldRemainLocked_whenExplicitlyLocked() 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.getForUpdate(key);
transactionalMap.replace(key, value);
assertTrue("Key remains unlocked!", map.isLocked(key));
return null;
}
});
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionLockingTest method testTxnRemoveIfSame_whenRemoveFails_keyShouldRemainLocked_whenExplicitlyLocked.
@Test
public void testTxnRemoveIfSame_whenRemoveFails_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.remove(key, "");
assertTrue("Key remains unlocked!", map.isLocked(key));
return null;
}
});
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class InterceptorTest method testInterceptPut_replicatedToBackups_usingTransactions.
@Test
public void testInterceptPut_replicatedToBackups_usingTransactions() {
final String name = randomString();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
Config config = getConfig();
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
HazelcastInstance hz2 = factory.newHazelcastInstance(config);
IMap<Object, Object> map = hz2.getMap(name);
map.addInterceptor(new NegativePutInterceptor());
final int count = 1000;
hz2.executeTransaction(new TransactionalTask<Object>() {
@Override
public Object execute(TransactionalTaskContext context) throws TransactionException {
TransactionalMap<Object, Object> txMap = context.getMap(name);
for (int i = 1; i <= count; i++) {
txMap.set(i, i);
}
return null;
}
});
waitAllForSafeState(hz1, hz2);
hz1.getLifecycleService().terminate();
for (int i = 1; i <= count; i++) {
assertEquals(-i, map.get(i));
}
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class TransactionalMapDeleteMessageTask method innerCall.
@Override
protected Object innerCall() throws Exception {
final TransactionContext context = endpoint.getTransactionContext(parameters.txnId);
final TransactionalMap map = context.getMap(parameters.name);
map.delete(parameters.key);
return null;
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class TransactionalMapReplaceIfSameMessageTask method innerCall.
@Override
protected Object innerCall() throws Exception {
final TransactionContext context = endpoint.getTransactionContext(parameters.txnId);
final TransactionalMap map = context.getMap(parameters.name);
return map.replace(parameters.key, parameters.oldValue, parameters.newValue);
}
Aggregations