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"));
}
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);
}
}
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());
}
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());
}
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));
}
Aggregations