Search in sources :

Example 1 with TransactionalMultiMap

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

the class ClientTxnMultiMapTest method testGet_whenBackedWithList.

@Test
public void testGet_whenBackedWithList() throws Exception {
    final String mapName = multiMapBackedByList + randomString();
    final String key = "key";
    final String value = "value";
    final MultiMap multiMap = server.getMultiMap(mapName);
    multiMap.put(key, value);
    TransactionContext tx = client.newTransactionContext();
    tx.beginTransaction();
    TransactionalMultiMap mulitMapTxn = tx.getMultiMap(mapName);
    Collection c = mulitMapTxn.get(key);
    assertFalse(c.isEmpty());
    tx.commitTransaction();
}
Also used : MultiMap(com.hazelcast.multimap.MultiMap) TransactionalMultiMap(com.hazelcast.transaction.TransactionalMultiMap) TransactionContext(com.hazelcast.transaction.TransactionContext) TransactionalMultiMap(com.hazelcast.transaction.TransactionalMultiMap) Collection(java.util.Collection) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with TransactionalMultiMap

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

the class ClientTxnMultiMapTest method testPutAndRoleBack.

@Test
public void testPutAndRoleBack() throws Exception {
    final String mapName = randomString();
    final String key = "key";
    final String value = "value";
    final MultiMap multiMap = client.getMultiMap(mapName);
    TransactionContext tx = client.newTransactionContext();
    tx.beginTransaction();
    TransactionalMultiMap mulitMapTxn = tx.getMultiMap(mapName);
    mulitMapTxn.put(key, value);
    mulitMapTxn.put(key, value);
    tx.rollbackTransaction();
    assertEquals(0, multiMap.get(key).size());
}
Also used : MultiMap(com.hazelcast.multimap.MultiMap) TransactionalMultiMap(com.hazelcast.transaction.TransactionalMultiMap) TransactionContext(com.hazelcast.transaction.TransactionContext) TransactionalMultiMap(com.hazelcast.transaction.TransactionalMultiMap) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with TransactionalMultiMap

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

the class ClientTxnMultiMapTest method testRemove.

@Test
public void testRemove() throws Exception {
    final String mapName = randomString();
    final String key = "key";
    final String val = "value";
    MultiMap multiMap = client.getMultiMap(mapName);
    multiMap.put(key, val);
    TransactionContext tx = client.newTransactionContext();
    tx.beginTransaction();
    TransactionalMultiMap txnMultiMap = tx.getMultiMap(mapName);
    txnMultiMap.remove(key, val);
    tx.commitTransaction();
    assertTrue(client.getMultiMap(mapName).get(key).isEmpty());
}
Also used : MultiMap(com.hazelcast.multimap.MultiMap) TransactionalMultiMap(com.hazelcast.transaction.TransactionalMultiMap) TransactionContext(com.hazelcast.transaction.TransactionContext) TransactionalMultiMap(com.hazelcast.transaction.TransactionalMultiMap) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with TransactionalMultiMap

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

the class ClientTxnMultiMapTest method testSize.

@Test
public void testSize() throws Exception {
    final String mapName = randomString();
    final String key = "key";
    final String value = "value";
    final MultiMap multiMap = client.getMultiMap(mapName);
    multiMap.put(key, value);
    TransactionContext tx = client.newTransactionContext();
    tx.beginTransaction();
    TransactionalMultiMap mulitMapTxn = tx.getMultiMap(mapName);
    mulitMapTxn.put(key, "newValue");
    mulitMapTxn.put("newKey", value);
    assertEquals(3, mulitMapTxn.size());
    tx.commitTransaction();
}
Also used : MultiMap(com.hazelcast.multimap.MultiMap) TransactionalMultiMap(com.hazelcast.transaction.TransactionalMultiMap) TransactionContext(com.hazelcast.transaction.TransactionContext) TransactionalMultiMap(com.hazelcast.transaction.TransactionalMultiMap) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with TransactionalMultiMap

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

the class ClientTxnMultiMapTest method testCount.

@Test
public void testCount() throws Exception {
    final String mapName = randomString();
    final String key = "key";
    final String value = "value";
    final MultiMap multiMap = client.getMultiMap(mapName);
    multiMap.put(key, value);
    TransactionContext tx = client.newTransactionContext();
    tx.beginTransaction();
    TransactionalMultiMap mulitMapTxn = tx.getMultiMap(mapName);
    mulitMapTxn.put(key, "newValue");
    assertEquals(2, mulitMapTxn.valueCount(key));
    tx.commitTransaction();
}
Also used : MultiMap(com.hazelcast.multimap.MultiMap) TransactionalMultiMap(com.hazelcast.transaction.TransactionalMultiMap) TransactionContext(com.hazelcast.transaction.TransactionContext) TransactionalMultiMap(com.hazelcast.transaction.TransactionalMultiMap) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 TransactionalMultiMap (com.hazelcast.transaction.TransactionalMultiMap)9 Test (org.junit.Test)9 MultiMap (com.hazelcast.multimap.MultiMap)8 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)8 TransactionContext (com.hazelcast.transaction.TransactionContext)8 TransactionException (com.hazelcast.transaction.TransactionException)2 Collection (java.util.Collection)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 TransactionalTaskContext (com.hazelcast.transaction.TransactionalTaskContext)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1