Search in sources :

Example 61 with TransactionalMap

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

the class ClientTxnMapTest method testDeadLockFromClientInstance.

@Test
public void testDeadLockFromClientInstance() throws InterruptedException {
    final String mapName = randomString();
    final String key = "key";
    final AtomicBoolean running = new AtomicBoolean(true);
    Thread t = new Thread() {

        public void run() {
            while (running.get()) {
                client.getMap(mapName).get(key);
            }
        }
    };
    t.start();
    CBAuthorisation cb = new CBAuthorisation();
    cb.setAmount(15000);
    try {
        TransactionContext context = client.newTransactionContext();
        context.beginTransaction();
        TransactionalMap mapTransaction = context.getMap(mapName);
        // init data
        mapTransaction.put(key, cb);
        // start test deadlock, 3 set and concurrent, get deadlock
        cb.setAmount(12000);
        mapTransaction.set(key, cb);
        cb.setAmount(10000);
        mapTransaction.set(key, cb);
        cb.setAmount(900);
        mapTransaction.set(key, cb);
        cb.setAmount(800);
        mapTransaction.set(key, cb);
        cb.setAmount(700);
        mapTransaction.set(key, cb);
        context.commitTransaction();
    } catch (TransactionException e) {
        e.printStackTrace();
        fail();
    }
    running.set(false);
    t.join();
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransactionException(com.hazelcast.transaction.TransactionException) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 62 with TransactionalMap

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

the class ClientTxnMapTest method testTnxMapRemoveKeyValue.

@Test
public void testTnxMapRemoveKeyValue() throws Exception {
    final String mapName = randomString();
    final String key1 = "key1";
    final String oldValue1 = "old1";
    final String key2 = "key2";
    final String oldValue2 = "old2";
    IMap map = client.getMap(mapName);
    map.put(key1, oldValue1);
    map.put(key2, oldValue2);
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    final TransactionalMap txMap = context.getMap(mapName);
    txMap.remove(key1, oldValue1);
    txMap.remove(key2, "NO_REMOVE_AS_NOT_VALUE");
    context.commitTransaction();
    assertNull(map.get(key1));
    assertEquals(oldValue2, map.get(key2));
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) IMap(com.hazelcast.map.IMap) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 63 with TransactionalMap

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

the class ClientTxnMapTest method testTnxMapReplace.

@Test
public void testTnxMapReplace() throws Exception {
    final String mapName = randomString();
    IMap map = client.getMap(mapName);
    final String key1 = "key1";
    final String key2 = "key2";
    final String replaceValue = "replaceValue";
    map.put(key1, "OLD_VALUE");
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    final TransactionalMap txMap = context.getMap(mapName);
    txMap.replace(key1, replaceValue);
    txMap.replace(key2, "NOT_POSSIBLE");
    context.commitTransaction();
    assertEquals(replaceValue, map.get(key1));
    assertNull(map.get(key2));
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) IMap(com.hazelcast.map.IMap) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 64 with TransactionalMap

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

the class TransactionsWithWriteBehind_whenNoCoalescingQueueIsFullTest method commit_step_does_not_throw_reached_max_size_exception_when_two_phase.

@Test
public void commit_step_does_not_throw_reached_max_size_exception_when_two_phase() {
    String mapName = "map";
    long maxWbqCapacity = 10;
    int keySpace = 10;
    Config config = getConfig(mapName, maxWbqCapacity);
    HazelcastInstance node = createHazelcastInstance(config);
    TransactionContext context = newTransactionContext(node, TWO_PHASE);
    context.beginTransaction();
    TransactionalMap txMap = context.getMap(mapName);
    for (int i = 0; i < keySpace; i++) {
        txMap.remove("item-" + i);
    }
    try {
        context.commitTransaction();
    } catch (TransactionException e) {
        fail("no txn exception is expected here...");
    }
    assertEquals(0, node.getMap(mapName).size());
    assertWriteBehindQueuesEmpty(mapName, Collections.singletonList(node));
    assertEquals(0, getTotalNumOfTxnReservedCapacity(mapName, node));
    assertEquals(0, getNodeWideUsedCapacity(node));
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) Config(com.hazelcast.config.Config) TransactionContext(com.hazelcast.transaction.TransactionContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 65 with TransactionalMap

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

the class TransactionsWithWriteBehind_whenNoCoalescingQueueIsFullTest method rollback_does_not_preserve_latest_state_after_reached_max_size_exception_when_one_phase.

@Ignore
@Test
public void rollback_does_not_preserve_latest_state_after_reached_max_size_exception_when_one_phase() {
    String mapName = "map";
    long maxWbqCapacity = 100;
    Config config = getConfig(mapName, maxWbqCapacity);
    HazelcastInstance node = createHazelcastInstance(config);
    TransactionContext context = newTransactionContext(node, ONE_PHASE);
    context.beginTransaction();
    TransactionalMap map = context.getMap(mapName);
    for (int i = 0; i < 101; i++) {
        map.put("item-" + i, "value");
    }
    try {
        context.commitTransaction();
    } catch (TransactionException e) {
        context.rollbackTransaction();
    }
    assertEquals(100, node.getMap(mapName).size());
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) Config(com.hazelcast.config.Config) TransactionContext(com.hazelcast.transaction.TransactionContext) Ignore(org.junit.Ignore) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

TransactionalMap (com.hazelcast.transaction.TransactionalMap)95 Test (org.junit.Test)77 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)76 QuickTest (com.hazelcast.test.annotation.QuickTest)76 HazelcastInstance (com.hazelcast.core.HazelcastInstance)63 TransactionException (com.hazelcast.transaction.TransactionException)60 TransactionalTaskContext (com.hazelcast.transaction.TransactionalTaskContext)55 NightlyTest (com.hazelcast.test.annotation.NightlyTest)42 Config (com.hazelcast.config.Config)39 TransactionContext (com.hazelcast.transaction.TransactionContext)38 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)37 MapStoreConfig (com.hazelcast.config.MapStoreConfig)32 IMap (com.hazelcast.map.IMap)28 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)27 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)14 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)7 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)6 TransactionNotActiveException (com.hazelcast.transaction.TransactionNotActiveException)6 Collection (java.util.Collection)6 ExecutionException (java.util.concurrent.ExecutionException)6