Search in sources :

Example 1 with TransactionalMap

use of com.hazelcast.core.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.core.TransactionalMap) IMap(com.hazelcast.core.IMap) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with TransactionalMap

use of com.hazelcast.core.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.core.TransactionalMap) IMap(com.hazelcast.core.IMap) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with TransactionalMap

use of com.hazelcast.core.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 SampleObjects.Employee emp1 = new SampleObjects.Employee("abc-123-xvz", 34, true, 10D);
    final SampleObjects.Employee emp2 = new SampleObjects.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(new SqlPredicate("age = 10")).size());
    assertEquals(0, txMap.values(new SqlPredicate("age = 10")).size());
    assertEquals(2, txMap.keySet(new SqlPredicate("age >= 10")).size());
    assertEquals(2, txMap.values(new SqlPredicate("age >= 10")).size());
    context.commitTransaction();
    assertEquals(2, map.size());
    assertEquals(2, map.values().size());
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) IMap(com.hazelcast.core.IMap) SampleObjects(com.hazelcast.query.SampleObjects) TransactionContext(com.hazelcast.transaction.TransactionContext) SqlPredicate(com.hazelcast.query.SqlPredicate) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with TransactionalMap

use of com.hazelcast.core.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.core.TransactionalMap) IMap(com.hazelcast.core.IMap) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with TransactionalMap

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

the class ClientTxnMapTest method testTnxMapDelete.

@Test
public void testTnxMapDelete() 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.delete(key);
    context.commitTransaction();
    assertNull(map.get(key));
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) IMap(com.hazelcast.core.IMap) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) 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