Search in sources :

Example 11 with IMap

use of com.hazelcast.map.IMap 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 12 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class ClientTxnMapTest method testTxnMapGet_BeforeCommit.

@Test
public void testTxnMapGet_BeforeCommit() throws Exception {
    final String mapName = randomString();
    final String key = "key";
    final String value = "Value";
    final IMap map = client.getMap(mapName);
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    final TransactionalMap<Object, Object> txnMap = context.getMap(mapName);
    txnMap.put(key, value);
    assertEquals(value, txnMap.get(key));
    assertNull(map.get(key));
    context.commitTransaction();
}
Also used : 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 13 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class ClientTxnMapTest method testPutAndRoleBack.

@Test
public void testPutAndRoleBack() throws Exception {
    final String mapName = randomString();
    final String key = "key";
    final String value = "value";
    final IMap map = client.getMap(mapName);
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    final TransactionalMap<Object, Object> mapTxn = context.getMap(mapName);
    mapTxn.put(key, value);
    context.rollbackTransaction();
    assertNull(map.get(key));
}
Also used : 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 14 with IMap

use of com.hazelcast.map.IMap 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 15 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class ClientTxnMapTest method testTxnMapPut.

@Test
public void testTxnMapPut() throws Exception {
    final String mapName = randomString();
    final String key = "key";
    final String value = "Value";
    final IMap map = client.getMap(mapName);
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    final TransactionalMap<Object, Object> txnMap = context.getMap(mapName);
    txnMap.put(key, value);
    context.commitTransaction();
    assertEquals(value, map.get(key));
}
Also used : 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

IMap (com.hazelcast.map.IMap)294 Test (org.junit.Test)259 QuickTest (com.hazelcast.test.annotation.QuickTest)237 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)228 HazelcastInstance (com.hazelcast.core.HazelcastInstance)139 Config (com.hazelcast.config.Config)103 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)82 Map (java.util.Map)75 CountDownLatch (java.util.concurrent.CountDownLatch)65 MapStoreConfig (com.hazelcast.config.MapStoreConfig)54 Category (org.junit.experimental.categories.Category)51 Assert.assertEquals (org.junit.Assert.assertEquals)50 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)48 HashMap (java.util.HashMap)48 Collection (java.util.Collection)41 RunWith (org.junit.runner.RunWith)41 MapConfig (com.hazelcast.config.MapConfig)36 Set (java.util.Set)34 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)33 AssertTask (com.hazelcast.test.AssertTask)32