use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.
the class ClientTxnTest method testRollbackOnTimeout.
@Test
public void testRollbackOnTimeout() {
String name = randomString();
IQueue<Object> queue = client.getQueue(name);
queue.offer(randomString());
TransactionOptions options = new TransactionOptions().setTimeout(3, TimeUnit.SECONDS);
TransactionContext context = client.newTransactionContext(options);
context.beginTransaction();
try {
context.getQueue(name).take();
sleepAtLeastSeconds(5);
context.commitTransaction();
fail();
} catch (Exception e) {
context.rollbackTransaction();
}
assertEquals("Queue size should be 1", 1, queue.size());
}
use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.
the class TransactionContextImpl_backupLogsTest method assertBackupLogCreationNotForced.
public void assertBackupLogCreationNotForced(String serviceName) {
TransactionOptions options = new TransactionOptions();
TransactionContextImpl txContext = new TransactionContextImpl(localTxManager, localNodeEngine, options, ownerUuid, false);
txContext.beginTransaction();
TransactionalObject result = txContext.getTransactionalObject(serviceName, "foo");
assertNotNull(result);
assertNull(remoteTxManager.txBackupLogs.get(txContext.getTxnId()));
}
use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.
the class TransactionImpl_OnePhaseTest method setup.
@Before
public void setup() {
HazelcastInstance hz = createHazelcastInstance();
operationService = getOperationService(hz);
logger = mock(ILogger.class);
txManagerService = mock(TransactionManagerServiceImpl.class);
txManagerService.commitCount = MwCounter.newMwCounter();
txManagerService.startCount = MwCounter.newMwCounter();
txManagerService.rollbackCount = MwCounter.newMwCounter();
nodeEngine = mock(NodeEngine.class);
when(nodeEngine.getOperationService()).thenReturn(operationService);
when(nodeEngine.getLocalMember()).thenReturn(new MemberImpl());
when(nodeEngine.getLogger(TransactionImpl.class)).thenReturn(logger);
options = new TransactionOptions().setTransactionType(ONE_PHASE);
}
use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.
the class TransactionImpl_TwoPhaseIntegrationTest method prepare_whenSingleItemAndDurabilityOne_thenNoBackupLog.
// =================== prepare ===========================================
@Test
public void prepare_whenSingleItemAndDurabilityOne_thenNoBackupLog() {
TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(1);
TransactionImpl tx = new TransactionImpl(localTxService, localNodeEngine, options, txOwner);
tx.begin();
MockTransactionLogRecord record = new MockTransactionLogRecord();
tx.add(record);
tx.prepare();
assertPrepared(tx);
assertNoBackupLogOnRemote(tx);
record.assertPrepareCalled().assertCommitNotCalled().assertRollbackNotCalled();
}
use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.
the class TransactionImpl_TwoPhaseIntegrationTest method rollback_whenMultipleItemsAndDurabilityZero_thenNoBackupLog.
@Test
public void rollback_whenMultipleItemsAndDurabilityZero_thenNoBackupLog() {
TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(0);
TransactionImpl tx = new TransactionImpl(localTxService, localNodeEngine, options, txOwner);
tx.begin();
MockTransactionLogRecord record1 = new MockTransactionLogRecord();
tx.add(record1);
MockTransactionLogRecord record2 = new MockTransactionLogRecord();
tx.add(record2);
tx.prepare();
tx.rollback();
assertRolledBack(tx);
assertNoBackupLogOnRemote(tx);
record1.assertPrepareCalled().assertCommitNotCalled().assertRollbackCalled();
record2.assertPrepareCalled().assertCommitNotCalled().assertRollbackCalled();
}
Aggregations