Search in sources :

Example 61 with TransactionalMap

use of com.hazelcast.core.TransactionalMap 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));
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 62 with TransactionalMap

use of com.hazelcast.core.TransactionalMap 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;
        }
    });
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 63 with TransactionalMap

use of com.hazelcast.core.TransactionalMap 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;
        }
    });
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 64 with TransactionalMap

use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.

the class MapTransactionLockingTest method testTxnPutIfAbsent_whenPutFails_keyShouldRemainUnlocked.

@Test
public void testTxnPutIfAbsent_whenPutFails_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.putIfAbsent(key, "t");
            return null;
        }
    });
    assertFalse("Key remains locked!", map.isLocked(key));
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 65 with TransactionalMap

use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.

the class MapTransactionLockingTest method testTxnRemoveIfSame_whenRemoveFails_keyShouldRemainUnlocked.

@Test
public void testTxnRemoveIfSame_whenRemoveFails_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.remove(key, value + "other");
            return null;
        }
    });
    assertFalse("Key remains locked!", map.isLocked(key));
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

TransactionalMap (com.hazelcast.core.TransactionalMap)92 Test (org.junit.Test)73 QuickTest (com.hazelcast.test.annotation.QuickTest)68 ParallelTest (com.hazelcast.test.annotation.ParallelTest)67 HazelcastInstance (com.hazelcast.core.HazelcastInstance)61 TransactionException (com.hazelcast.transaction.TransactionException)60 TransactionalTaskContext (com.hazelcast.transaction.TransactionalTaskContext)59 NightlyTest (com.hazelcast.test.annotation.NightlyTest)47 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)38 Config (com.hazelcast.config.Config)36 TransactionContext (com.hazelcast.transaction.TransactionContext)33 MapStoreConfig (com.hazelcast.config.MapStoreConfig)32 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)30 IMap (com.hazelcast.core.IMap)29 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)12 SqlPredicate (com.hazelcast.query.SqlPredicate)8 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)7 Collection (java.util.Collection)7 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)6 TransactionNotActiveException (com.hazelcast.transaction.TransactionNotActiveException)6