use of org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method testMarkRollbackOnly.
@Test
@SuppressWarnings("EmptyCatchBlock")
public void testMarkRollbackOnly() throws Exception {
JtaTransactionCoordinatorImpl transactionCoordinator = new JtaTransactionCoordinatorImpl(transactionCoordinatorBuilder, owner, true, JtaPlatformStandardTestingImpl.INSTANCE, preferUserTransactions(), true);
// pre conditions
final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
transactionCoordinator.getTransactionDriverControl().begin();
assertEquals(TransactionStatus.ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
transactionCoordinator.getTransactionDriverControl().markRollbackOnly();
assertEquals(TransactionStatus.MARKED_ROLLBACK, transactionCoordinator.getTransactionDriverControl().getStatus());
try {
transactionCoordinator.getTransactionDriverControl().commit();
} catch (TransactionException expected) {
} finally {
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
}
}
use of org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method testSynchronizationFailure.
@Test
@SuppressWarnings("EmptyCatchBlock")
public void testSynchronizationFailure() throws Exception {
JtaTransactionCoordinatorImpl transactionCoordinator = new JtaTransactionCoordinatorImpl(transactionCoordinatorBuilder, owner, true, JtaPlatformStandardTestingImpl.INSTANCE, preferUserTransactions(), true);
// pre conditions
final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
transactionCoordinator.getLocalSynchronizations().registerSynchronization(SynchronizationErrorImpl.forBefore());
transactionCoordinator.getTransactionDriverControl().begin();
assertEquals(TransactionStatus.ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
try {
transactionCoordinator.getTransactionDriverControl().commit();
} catch (Exception expected) {
} finally {
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
}
}
use of org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl in project hibernate-orm by hibernate.
the class InaccessibleJtaPlatformTests method testInaccessibleUserTransactionHandling.
@Test
public void testInaccessibleUserTransactionHandling() {
// first, have JtaPlatform throw an exception
try {
final JtaPlatformInaccessibleImpl jtaPlatform = new JtaPlatformInaccessibleImpl(true);
final TransactionCoordinator transactionCoordinator = new JtaTransactionCoordinatorImpl(transactionCoordinatorBuilder, owner, true, jtaPlatform, false, false);
transactionCoordinator.getTransactionDriverControl().begin();
fail("Expecting JtaPlatformInaccessibleException, but call succeeded");
} catch (JtaPlatformInaccessibleException expected) {
// expected condition
} catch (Exception e) {
fail("Expecting JtaPlatformInaccessibleException, but got " + e.getClass().getName());
}
// then, have it return null
try {
final JtaPlatformInaccessibleImpl jtaPlatform = new JtaPlatformInaccessibleImpl(false);
final TransactionCoordinator transactionCoordinator = new JtaTransactionCoordinatorImpl(transactionCoordinatorBuilder, owner, true, jtaPlatform, false, false);
transactionCoordinator.getTransactionDriverControl().begin();
fail("Expecting JtaPlatformInaccessibleException, but call succeeded");
} catch (JtaPlatformInaccessibleException expected) {
// expected condition
} catch (Exception e) {
fail("Expecting JtaPlatformInaccessibleException, but got " + e.getClass().getName());
}
}
use of org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method basicBmtUsageTest.
@Test
public void basicBmtUsageTest() throws Exception {
final JtaTransactionCoordinatorImpl transactionCoordinator = buildTransactionCoordinator(true);
// pre conditions
final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertFalse(transactionCoordinator.isSynchronizationRegistered());
// begin the transaction
transactionCoordinator.getTransactionDriverControl().begin();
assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
assertTrue(transactionCoordinator.isSynchronizationRegistered());
// create and add a local Synchronization
SynchronizationCollectorImpl localSync = new SynchronizationCollectorImpl();
transactionCoordinator.getLocalSynchronizations().registerSynchronization(localSync);
// commit the transaction
transactionCoordinator.getTransactionDriverControl().commit();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertFalse(transactionCoordinator.isSynchronizationRegistered());
assertEquals(1, localSync.getBeforeCompletionCount());
assertEquals(1, localSync.getSuccessfulCompletionCount());
assertEquals(0, localSync.getFailedCompletionCount());
}
use of org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method basicCmtUsageTest.
@Test
public void basicCmtUsageTest() throws Exception {
// pre conditions
final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
// begin the transaction
tm.begin();
final JtaTransactionCoordinatorImpl transactionCoordinator = buildTransactionCoordinator(true);
assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
// NOTE : because of auto-join
assertTrue(transactionCoordinator.isSynchronizationRegistered());
// create and add a local Synchronization
SynchronizationCollectorImpl localSync = new SynchronizationCollectorImpl();
transactionCoordinator.getLocalSynchronizations().registerSynchronization(localSync);
// commit the transaction
tm.commit();
// post conditions
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertFalse(transactionCoordinator.isSynchronizationRegistered());
assertEquals(1, localSync.getBeforeCompletionCount());
assertEquals(1, localSync.getSuccessfulCompletionCount());
assertEquals(0, localSync.getFailedCompletionCount());
}
Aggregations