Search in sources :

Example 31 with TransactionOptions

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

the class TransactionalMapReadQuorumTest method parameters.

@Parameterized.Parameters(name = "Executing: {0}")
public static Collection<Object[]> parameters() {
    TransactionOptions onePhaseOption = TransactionOptions.getDefault();
    onePhaseOption.setTransactionType(ONE_PHASE);
    TransactionOptions twoPhaseOption = TransactionOptions.getDefault();
    twoPhaseOption.setTransactionType(TWO_PHASE);
    return Arrays.asList(new Object[] { twoPhaseOption }, new Object[] { onePhaseOption });
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions)

Example 32 with TransactionOptions

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

the class TransactionalMapWriteQuorumTest method parameters.

@Parameterized.Parameters(name = "Executing: {0}")
public static Collection<Object[]> parameters() {
    TransactionOptions onePhase = TransactionOptions.getDefault();
    onePhase.setTransactionType(ONE_PHASE);
    TransactionOptions twoPhaseOption = TransactionOptions.getDefault();
    twoPhaseOption.setTransactionType(TWO_PHASE);
    return Arrays.asList(new Object[] { twoPhaseOption }, new Object[] { onePhase });
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions)

Example 33 with TransactionOptions

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

the class TransactionCreateMessageTask method innerCall.

@Override
protected Object innerCall() throws Exception {
    TransactionOptions options = new TransactionOptions();
    options.setDurability(parameters.durability);
    options.setTimeout(parameters.timeout, TimeUnit.MILLISECONDS);
    options.setTransactionType(TransactionOptions.TransactionType.getByValue(parameters.transactionType));
    TransactionManagerServiceImpl transactionManager = (TransactionManagerServiceImpl) clientEngine.getTransactionManagerService();
    TransactionContext context = transactionManager.newClientTransactionContext(options, endpoint.getUuid());
    context.beginTransaction();
    endpoint.setTransactionContext(context);
    return context.getTxnId();
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl) TransactionContext(com.hazelcast.transaction.TransactionContext)

Example 34 with TransactionOptions

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

the class AdvancedClusterStateTest method changeClusterState_shouldFail_withoutBackup_whenInitiatorDies_beforePrepare.

@Test
public void changeClusterState_shouldFail_withoutBackup_whenInitiatorDies_beforePrepare() throws Exception {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance[] instances = factory.newInstances();
    final HazelcastInstance hz = instances[instances.length - 1];
    TransactionManagerServiceImpl transactionManagerService = spyTransactionManagerService(hz);
    TransactionOptions options = new TransactionOptions().setDurability(0).setTimeout(30, TimeUnit.SECONDS);
    when(transactionManagerService.newAllowedDuringPassiveStateTransaction(options)).thenAnswer(new TransactionAnswer() {

        @Override
        protected void beforePrepare() {
            terminateInstance(hz);
        }
    });
    try {
        hz.getCluster().changeClusterState(ClusterState.FROZEN, options);
        fail("This instance is terminated. Cannot commit the transaction!");
    } catch (HazelcastInstanceNotActiveException ignored) {
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertClusterState(ClusterState.ACTIVE, instances[0], instances[1]);
        }
    });
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl) TransactionOptions(com.hazelcast.transaction.TransactionOptions) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) TransactionException(com.hazelcast.transaction.TransactionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 35 with TransactionOptions

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

the class AdvancedClusterStateTest method changeClusterState_shouldNotFail_whenInitiatorDies_afterPrepare.

@Test
public void changeClusterState_shouldNotFail_whenInitiatorDies_afterPrepare() throws Exception {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance[] instances = factory.newInstances();
    final HazelcastInstance hz = instances[instances.length - 1];
    TransactionManagerServiceImpl transactionManagerService = spyTransactionManagerService(hz);
    TransactionOptions options = TransactionOptions.getDefault().setDurability(1);
    when(transactionManagerService.newAllowedDuringPassiveStateTransaction(options)).thenAnswer(new TransactionAnswer() {

        @Override
        protected void afterPrepare() {
            terminateInstance(hz);
        }
    });
    try {
        hz.getCluster().changeClusterState(ClusterState.FROZEN, options);
        fail("This instance is terminated. Cannot commit the transaction!");
    } catch (HazelcastInstanceNotActiveException ignored) {
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertClusterState(ClusterState.FROZEN, instances[0], instances[1]);
        }
    });
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl) TransactionOptions(com.hazelcast.transaction.TransactionOptions) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) TransactionException(com.hazelcast.transaction.TransactionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

TransactionOptions (com.hazelcast.transaction.TransactionOptions)47 QuickTest (com.hazelcast.test.annotation.QuickTest)36 Test (org.junit.Test)36 TransactionException (com.hazelcast.transaction.TransactionException)18 HazelcastInstance (com.hazelcast.core.HazelcastInstance)15 ParallelTest (com.hazelcast.test.annotation.ParallelTest)14 AssertTask (com.hazelcast.test.AssertTask)9 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)9 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)7 TransactionManagerServiceImpl (com.hazelcast.transaction.impl.TransactionManagerServiceImpl)7 ExecutionException (java.util.concurrent.ExecutionException)7 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)6 TransactionContext (com.hazelcast.transaction.TransactionContext)6 Config (com.hazelcast.config.Config)3 NightlyTest (com.hazelcast.test.annotation.NightlyTest)3 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 TransactionalMap (com.hazelcast.core.TransactionalMap)2 MemberImpl (com.hazelcast.instance.MemberImpl)2 ILogger (com.hazelcast.logging.ILogger)2 Address (com.hazelcast.nio.Address)2