Search in sources :

Example 6 with TransactionalMap

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

the class ClientTxnMapTest method testKeysetAndValuesWithPredicates.

@Test
public void testKeysetAndValuesWithPredicates() throws Exception {
    final String mapName = randomString();
    IMap map = client.getMap(mapName);
    final SampleTestObjects.Employee emp1 = new SampleTestObjects.Employee("abc-123-xvz", 34, true, 10D);
    final SampleTestObjects.Employee emp2 = new SampleTestObjects.Employee("abc-123-xvz", 20, true, 10D);
    map.put(emp1, emp1);
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    final TransactionalMap txMap = context.getMap(mapName);
    assertNull(txMap.put(emp2, emp2));
    assertEquals(2, txMap.size());
    assertEquals(2, txMap.keySet().size());
    assertEquals(0, txMap.keySet(Predicates.sql("age = 10")).size());
    assertEquals(0, txMap.values(Predicates.sql("age = 10")).size());
    assertEquals(2, txMap.keySet(Predicates.sql("age >= 10")).size());
    assertEquals(2, txMap.values(Predicates.sql("age >= 10")).size());
    context.commitTransaction();
    assertEquals(2, map.size());
    assertEquals(2, map.values().size());
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) IMap(com.hazelcast.map.IMap) TransactionContext(com.hazelcast.transaction.TransactionContext) SampleTestObjects(com.hazelcast.query.SampleTestObjects) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with TransactionalMap

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

the class ClientTxnMapTest method testTnxMapPutIfAbsent.

@Test
public void testTnxMapPutIfAbsent() throws Exception {
    final String mapName = randomString();
    IMap map = client.getMap(mapName);
    final String keyValue1 = "keyValue1";
    final String keyValue2 = "keyValue2";
    map.put(keyValue1, keyValue1);
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    final TransactionalMap txMap = context.getMap(mapName);
    txMap.putIfAbsent(keyValue1, "NOT_THIS");
    txMap.putIfAbsent(keyValue2, keyValue2);
    context.commitTransaction();
    assertEquals(keyValue1, map.get(keyValue1));
    assertEquals(keyValue2, map.get(keyValue2));
}
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 8 with TransactionalMap

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

the class ClientTxnMapTest method testTnxMapIsEmpty.

@Test
public void testTnxMapIsEmpty() throws Exception {
    final String mapName = randomString();
    IMap map = client.getMap(mapName);
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    final TransactionalMap txMap = context.getMap(mapName);
    assertTrue(txMap.isEmpty());
    context.commitTransaction();
}
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 9 with TransactionalMap

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

the class ClientTxnMapTest method testTnxMapReplaceKeyValue.

@Test
public void testTnxMapReplaceKeyValue() throws Exception {
    final String mapName = randomString();
    final String key1 = "key1";
    final String oldValue1 = "old1";
    final String newValue1 = "new1";
    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.replace(key1, oldValue1, newValue1);
    txMap.replace(key2, "NOT_OLD_VALUE", "NEW_VALUE_CANT_BE_THIS");
    context.commitTransaction();
    assertEquals(newValue1, 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 10 with TransactionalMap

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

the class ClientTxnMapTest method testTnxMapRemove.

@Test
public void testTnxMapRemove() throws Exception {
    final String mapName = randomString();
    final String key = "key1";
    final String value = "old1";
    IMap map = client.getMap(mapName);
    map.put(key, value);
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    final TransactionalMap txMap = context.getMap(mapName);
    txMap.remove(key);
    context.commitTransaction();
    assertNull(map.get(key));
}
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)

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