Search in sources :

Example 1 with TransactionalMap

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

the class ClientXATest method testRollback.

@Test
public void testRollback() throws Exception {
    Hazelcast.newHazelcastInstance();
    HazelcastInstance client = HazelcastClient.newHazelcastClient();
    HazelcastXAResource xaResource = client.getXAResource();
    tm.begin();
    Transaction transaction = tm.getTransaction();
    transaction.enlistResource(xaResource);
    TransactionContext context = xaResource.getTransactionContext();
    boolean error = false;
    try {
        final TransactionalMap m = context.getMap("m");
        m.put("key", "value");
        throw new RuntimeException("Exception for rolling back");
    } catch (Exception e) {
        error = true;
    } finally {
        close(error, xaResource);
    }
    assertNull(client.getMap("m").get("key"));
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Transaction(javax.transaction.Transaction) TransactionContext(com.hazelcast.transaction.TransactionContext) RollbackException(javax.transaction.RollbackException) SystemException(javax.transaction.SystemException) HazelcastXAResource(com.hazelcast.transaction.HazelcastXAResource) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 2 with TransactionalMap

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

the class ClientXATest method txn.

private void txn(HazelcastInstance instance) throws Exception {
    HazelcastXAResource xaResource = instance.getXAResource();
    tm.begin();
    Transaction transaction = tm.getTransaction();
    transaction.enlistResource(xaResource);
    boolean error = false;
    try {
        TransactionContext context = xaResource.getTransactionContext();
        TransactionalMap m = context.getMap("m");
        m.put(random.nextInt(10), "value");
    } catch (Exception e) {
        logger.severe("Exception during transaction", e);
        error = true;
    } finally {
        close(error, xaResource);
    }
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) Transaction(javax.transaction.Transaction) TransactionContext(com.hazelcast.transaction.TransactionContext) RollbackException(javax.transaction.RollbackException) SystemException(javax.transaction.SystemException) HazelcastXAResource(com.hazelcast.transaction.HazelcastXAResource)

Example 3 with TransactionalMap

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

the class ClientTxnMapTest method txn_map_containsKey_skips_server_side_near_cache.

@Test
public void txn_map_containsKey_skips_server_side_near_cache() {
    String mapName = "test";
    int keyInServerNearCache = 1;
    IMap serverMap = prepareServerAndGetServerMap(mapName, keyInServerNearCache);
    TransactionalMap clientTxnMap = getClientTransactionalMap(mapName);
    assertTrue(clientTxnMap.containsKey(keyInServerNearCache));
    assertEquals(0, serverMap.getLocalMapStats().getNearCacheStats().getHits());
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) IMap(com.hazelcast.map.IMap) 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 TransactionalMap

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

the class ClientTxnMapTest method txn_map_get_skips_server_side_near_cache.

@Test
public void txn_map_get_skips_server_side_near_cache() {
    String mapName = "test";
    int keyInServerNearCache = 1;
    IMap serverMap = prepareServerAndGetServerMap(mapName, keyInServerNearCache);
    TransactionalMap clientTxnMap = getClientTransactionalMap(mapName);
    assertNotNull(clientTxnMap.get(keyInServerNearCache));
    assertEquals(0, serverMap.getLocalMapStats().getNearCacheStats().getHits());
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) IMap(com.hazelcast.map.IMap) 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 TransactionalMap

use of com.hazelcast.transaction.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.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