use of com.hazelcast.transaction.TransactionalTaskContext in project hazelcast by hazelcast.
the class MapTransactionTest method tesPutIfAbsent_whenNullValue.
@Test(expected = NullPointerException.class)
public void tesPutIfAbsent_whenNullValue() 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("key", null);
return true;
}
});
}
use of com.hazelcast.transaction.TransactionalTaskContext in project hazelcast by hazelcast.
the class MapTransactionLockingTest method testTxnPutIfAbsent_whenPutFails_keyShouldRemainUnlockedDuringTransaction.
@Test
public void testTxnPutIfAbsent_whenPutFails_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.putIfAbsent(key, "t");
assertFalse("Key remains locked!", map.isLocked(key));
return null;
}
});
}
use of com.hazelcast.transaction.TransactionalTaskContext 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.TransactionalTaskContext 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.TransactionalTaskContext in project hazelcast by hazelcast.
the class SetAbstractTest method testNameBasedAffinity.
@Test
public void testNameBasedAffinity() {
//creates more instances to increase a chance 'foo' will not be owned by
//the same member as 'foo@1'
newInstances(config);
newInstances(config);
int numberOfSets = 100;
ISet[] localSets = new ISet[numberOfSets];
ISet[] targetSets = new ISet[numberOfSets];
for (int i = 0; i < numberOfSets; i++) {
String name = randomName() + "@" + i;
localSets[i] = local.getSet(name);
targetSets[i] = target.getSet(name);
}
for (final ISet set : localSets) {
TransactionalTask task = new TransactionalTask() {
@Override
public Object execute(TransactionalTaskContext context) throws TransactionException {
TransactionalSet<String> txSet = context.getSet(set.getName());
txSet.add("Hello");
return null;
}
};
local.executeTransaction(task);
}
for (ISet set : localSets) {
assertEquals(1, set.size());
}
}
Aggregations