use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class TxnLockAndGetOperation method run.
@Override
public void run() throws Exception {
if (!recordStore.txnLock(getKey(), ownerUuid, getThreadId(), getCallId(), ttl, blockReads)) {
throw new TransactionException("Transaction couldn't obtain lock.");
}
Record record = recordStore.getRecordOrNull(dataKey);
if (record == null && shouldLoad) {
record = recordStore.loadRecordOrNull(dataKey, false);
}
Data value = record == null ? null : mapServiceContext.toData(record.getValue());
response = new VersionedValue(value, record == null ? 0 : record.getVersion());
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class ClientTransactionManagerServiceImpl method executeTransaction.
@Override
public <T> T executeTransaction(TransactionOptions options, TransactionalTask<T> task) throws TransactionException {
final TransactionContext context = newTransactionContext(options);
context.beginTransaction();
try {
final T value = task.execute(context);
context.commitTransaction();
return value;
} catch (Throwable e) {
context.rollbackTransaction();
if (e instanceof TransactionException) {
throw (TransactionException) e;
}
if (e.getCause() instanceof TransactionException) {
throw (TransactionException) e.getCause();
}
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new TransactionException(e);
}
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class ClientTxnTest method testTxnRollbackOnServerCrash.
@Test
public void testTxnRollbackOnServerCrash() throws Exception {
final String queueName = randomString();
final TransactionContext context = client.newTransactionContext();
CountDownLatch txnRollbackLatch = new CountDownLatch(1);
final CountDownLatch memberRemovedLatch = new CountDownLatch(1);
context.beginTransaction();
final TransactionalQueue queue = context.getQueue(queueName);
queue.offer(randomString());
client.getCluster().addMembershipListener(new MembershipAdapter() {
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
memberRemovedLatch.countDown();
}
});
server.getLifecycleService().terminate();
try {
context.commitTransaction();
fail("commit should throw exception !");
} catch (TransactionException e) {
context.rollbackTransaction();
txnRollbackLatch.countDown();
}
assertOpenEventually(txnRollbackLatch);
assertOpenEventually(memberRemovedLatch);
final IQueue<Object> q = client.getQueue(queueName);
assertNull(q.poll());
assertEquals(0, q.size());
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class ClientTxnReconnectModeTest method testNewTransactionContext_ReconnectMode_ASYNC.
@Test(expected = HazelcastClientOfflineException.class)
public void testNewTransactionContext_ReconnectMode_ASYNC() throws Throwable {
ClientConfig config = new ClientConfig();
config.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
config.getNetworkConfig().setSmartRouting(smartRouting);
config.getConnectionStrategyConfig().setAsyncStart(true);
config.getConnectionStrategyConfig().setReconnectMode(ClientConnectionStrategyConfig.ReconnectMode.ASYNC);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
try {
client.newTransactionContext();
} catch (TransactionException e) {
throw e.getCause();
}
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class ClientTxnReconnectModeTest method testNewTransactionContext_After_shutdown.
@Test(expected = HazelcastClientNotActiveException.class)
public void testNewTransactionContext_After_shutdown() throws Throwable {
ClientConfig config = new ClientConfig();
config.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
config.getNetworkConfig().setSmartRouting(smartRouting);
config.getConnectionStrategyConfig().setAsyncStart(true);
config.getConnectionStrategyConfig().setReconnectMode(ClientConnectionStrategyConfig.ReconnectMode.ASYNC);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
client.shutdown();
try {
client.newTransactionContext();
} catch (TransactionException e) {
throw e.getCause();
}
}
Aggregations