use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.
the class TransactionImpl_TwoPhaseTest method rollback_whenAlreadyRolledBack.
@Test(expected = IllegalStateException.class)
public void rollback_whenAlreadyRolledBack() {
TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(0);
TransactionImpl tx = new TransactionImpl(txManagerService, nodeEngine, options, UUID.randomUUID());
tx.begin();
tx.rollback();
tx.rollback();
}
use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.
the class MapTransactionTest method testTransactionAtomicity_withMapAndQueue.
@Test
public void testTransactionAtomicity_withMapAndQueue() throws ExecutionException, InterruptedException {
final HazelcastInstance instance = createHazelcastInstance();
Future<Object> future = spawn(new Callable<Object>() {
@Override
public Object call() throws Exception {
IQueue<Object> queue = instance.getQueue("queue");
IMap<Object, Object> map = instance.getMap("map");
Object item = queue.take();
return map.get(item);
}
});
TransactionOptions options = new TransactionOptions().setTransactionType(TransactionOptions.TransactionType.ONE_PHASE);
TransactionContext context = instance.newTransactionContext(options);
context.beginTransaction();
TransactionalQueue<Object> queue = context.getQueue("queue");
TransactionalMap<Object, Object> map = context.getMap("map");
queue.offer("item-99");
for (int i = 0; i < 100; i++) {
map.put("item-" + i, "value");
}
context.commitTransaction();
assertEquals("value", future.get());
}
use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.
the class TxnMapNearCacheInvalidationTest method after_txn_commit_near_cache_should_be_invalidated.
@Test
public void after_txn_commit_near_cache_should_be_invalidated() {
Config cfg = getConfig();
String mapName = "cache";
MapConfig cacheConfig = cfg.getMapConfig(mapName);
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setInvalidateOnChange(true).setCacheLocalEntries(true).setInMemoryFormat(inMemoryFormat).setSerializeKeys(serializeKeys);
cacheConfig.setNearCacheConfig(nearCacheConfig);
HazelcastInstance server = createHazelcastInstance(cfg);
IMap map = server.getMap(mapName);
String key = "key";
String oldValue = "oldValue";
String updatedValue = "updatedValue";
// populate imap
map.put(key, oldValue);
// populate near cache
Object valueReadBeforeTxnFromNonTxnMap = map.get(key);
// begin txn
TransactionOptions opts = new TransactionOptions();
opts.setTransactionType(TransactionOptions.TransactionType.TWO_PHASE);
TransactionContext ctx = server.newTransactionContext(opts);
ctx.beginTransaction();
TransactionalMap txnMap = ctx.getMap(mapName);
Object valueReadInsideTxnFromTxnMapBeforeUpdate = txnMap.get(key);
txnMap.put(key, updatedValue);
Object valueReadInsideTxnFromTxnMapAfterUpdate = txnMap.get(key);
Object valueReadInsideTxnFromNonTxnMapAfterUpdate = map.get(key);
ctx.commitTransaction();
// check values read from txn map
assertEquals(oldValue, valueReadInsideTxnFromTxnMapBeforeUpdate);
assertEquals(updatedValue, valueReadInsideTxnFromTxnMapAfterUpdate);
// check values read from non-txn map
assertEquals(oldValue, valueReadBeforeTxnFromNonTxnMap);
assertEquals(oldValue, valueReadInsideTxnFromNonTxnMapAfterUpdate);
Object valueReadAfterTxnFromNonTxnMap = map.get(key);
assertEquals(updatedValue, valueReadAfterTxnFromNonTxnMap);
}
use of com.hazelcast.transaction.TransactionOptions in project hazelcast-simulator by hazelcast.
the class MapTransactionContextTest method timestep.
@TimeStep
public void timestep(ThreadState state) {
int key = state.nextRandom(0, range / 2);
TransactionOptions transactionOptions = new TransactionOptions().setTransactionType(transactionType).setDurability(durability);
TransactionContext transactionContext = targetInstance.newTransactionContext(transactionOptions);
transactionContext.beginTransaction();
TransactionalMap<Object, Object> txMap = transactionContext.getMap("map");
try {
Object val = txMap.getForUpdate(key);
if (val != null) {
key = state.nextRandom(range / 2, range);
}
txMap.put(key, (long) key);
transactionContext.commitTransaction();
} catch (Exception e) {
logger.fatal("----------------------tx exception -------------------------", e);
if (failOnException) {
throw rethrow(e);
}
transactionContext.rollbackTransaction();
}
}
Aggregations