Search in sources :

Example 71 with TransactionalMap

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

the class MapTransactionTest method testRemove.

@Test
public void testRemove() throws TransactionException {
    Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance h1 = factory.newHazelcastInstance(config);
    final HazelcastInstance h2 = factory.newHazelcastInstance(config);
    final IMap map1 = h1.getMap("default");
    final IMap map2 = h2.getMap("default");
    map2.put("1", "1");
    map2.put("2", "2");
    boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {

        public Boolean execute(TransactionalTaskContext context) throws TransactionException {
            final TransactionalMap<Object, Object> txMap = context.getMap("default");
            txMap.put("3", "3");
            map2.put("4", "4");
            assertEquals("1", txMap.remove("1"));
            assertEquals("2", map1.remove("2"));
            assertEquals("1", map1.get("1"));
            assertEquals(null, txMap.get("1"));
            assertEquals(null, txMap.remove("2"));
            assertEquals(2, txMap.size());
            return true;
        }
    });
    assertTrue(b);
    assertEquals(null, map1.get("1"));
    assertEquals(null, map2.get("1"));
    assertEquals(null, map1.get("2"));
    assertEquals(null, map2.get("2"));
    assertEquals("3", map1.get("3"));
    assertEquals("3", map2.get("3"));
    assertEquals("4", map1.get("4"));
    assertEquals("4", map2.get("4"));
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 72 with TransactionalMap

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

the class TransactionalMapSetMessageTask method innerCall.

@Override
protected Object innerCall() throws Exception {
    final TransactionContext context = getEndpoint().getTransactionContext(parameters.txnId);
    final TransactionalMap map = context.getMap(parameters.name);
    map.set(parameters.key, parameters.value);
    return null;
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) TransactionContext(com.hazelcast.transaction.TransactionContext)

Example 73 with TransactionalMap

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

the class TransactionalMapSizeMessageTask method innerCall.

@Override
protected Object innerCall() throws Exception {
    final TransactionContext context = getEndpoint().getTransactionContext(parameters.txnId);
    final TransactionalMap map = context.getMap(parameters.name);
    return map.size();
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) TransactionContext(com.hazelcast.transaction.TransactionContext)

Example 74 with TransactionalMap

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

the class TransactionalMapValuesMessageTask method innerCall.

@Override
protected Object innerCall() throws Exception {
    final TransactionContext context = getEndpoint().getTransactionContext(parameters.txnId);
    final TransactionalMap map = context.getMap(parameters.name);
    Collection values = map.values();
    List<Data> list = new ArrayList<Data>(values.size());
    for (Object o : values) {
        list.add(serializationService.toData(o));
    }
    return list;
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) TransactionContext(com.hazelcast.transaction.TransactionContext) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Data(com.hazelcast.nio.serialization.Data)

Example 75 with TransactionalMap

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

the class TransactionalMapValuesWithPredicateMessageTask method innerCall.

@Override
protected Object innerCall() throws Exception {
    final TransactionContext context = getEndpoint().getTransactionContext(parameters.txnId);
    final TransactionalMap map = context.getMap(parameters.name);
    Predicate predicate = serializationService.toObject(parameters.predicate);
    Collection values = map.values(predicate);
    List<Data> list = new ArrayList<Data>(values.size());
    for (Object o : values) {
        list.add(serializationService.toData(o));
    }
    return list;
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) TransactionContext(com.hazelcast.transaction.TransactionContext) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Data(com.hazelcast.nio.serialization.Data) Predicate(com.hazelcast.query.Predicate)

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