use of org.hibernate.test.resource.common.SynchronizationCollectorImpl in project hibernate-orm by hibernate.
the class BasicJdbcTransactionTests method basicUsageTest.
@Test
public void basicUsageTest() throws Exception {
final TransactionCoordinatorOwnerTestingImpl owner = new TransactionCoordinatorOwnerTestingImpl();
final JdbcResourceLocalTransactionCoordinatorBuilderImpl transactionCoordinatorBuilder = new JdbcResourceLocalTransactionCoordinatorBuilderImpl();
final TransactionCoordinator transactionCoordinator = transactionCoordinatorBuilder.buildTransactionCoordinator(owner, new TransactionCoordinatorBuilder.Options() {
@Override
public boolean shouldAutoJoinTransaction() {
return false;
}
});
SynchronizationCollectorImpl sync = new SynchronizationCollectorImpl();
transactionCoordinator.getLocalSynchronizations().registerSynchronization(sync);
transactionCoordinator.getTransactionDriverControl().begin();
assertEquals(0, sync.getBeforeCompletionCount());
assertEquals(0, sync.getSuccessfulCompletionCount());
assertEquals(0, sync.getFailedCompletionCount());
transactionCoordinator.getTransactionDriverControl().commit();
assertEquals(1, sync.getBeforeCompletionCount());
assertEquals(1, sync.getSuccessfulCompletionCount());
assertEquals(0, sync.getFailedCompletionCount());
}
use of org.hibernate.test.resource.common.SynchronizationCollectorImpl in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method rollbackBmtUsageTest.
@Test
public void rollbackBmtUsageTest() 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);
// rollback the transaction
transactionCoordinator.getTransactionDriverControl().rollback();
// post conditions
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertFalse(transactionCoordinator.isSynchronizationRegistered());
assertEquals(0, localSync.getBeforeCompletionCount());
assertEquals(0, localSync.getSuccessfulCompletionCount());
assertEquals(1, localSync.getFailedCompletionCount());
}
use of org.hibernate.test.resource.common.SynchronizationCollectorImpl in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method assureMultipleJoinCallsNoOp.
@Test
public void assureMultipleJoinCallsNoOp() throws Exception {
// pre conditions
final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
// begin the transaction
tm.begin();
assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
final JtaTransactionCoordinatorImpl transactionCoordinator = buildTransactionCoordinator(false);
// no auto-join now
assertFalse(transactionCoordinator.isJoined());
transactionCoordinator.explicitJoin();
assertTrue(transactionCoordinator.isJoined());
transactionCoordinator.explicitJoin();
transactionCoordinator.explicitJoin();
transactionCoordinator.explicitJoin();
transactionCoordinator.explicitJoin();
assertTrue(transactionCoordinator.isJoined());
// 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());
}
use of org.hibernate.test.resource.common.SynchronizationCollectorImpl in project hibernate-orm by hibernate.
the class SynchronizationRegistryStandardImplTests method basicUsageTests.
@Test
public void basicUsageTests() {
final SynchronizationRegistryStandardImpl registry = new SynchronizationRegistryStandardImpl();
try {
registry.registerSynchronization(null);
fail("Was expecting NullSynchronizationException, but call succeeded");
} catch (NullSynchronizationException expected) {
// expected behavior
} catch (Exception e) {
fail("Was expecting NullSynchronizationException, but got " + e.getClass().getName());
}
final SynchronizationCollectorImpl synchronization = new SynchronizationCollectorImpl();
assertEquals(0, registry.getNumberOfRegisteredSynchronizations());
registry.registerSynchronization(synchronization);
assertEquals(1, registry.getNumberOfRegisteredSynchronizations());
registry.registerSynchronization(synchronization);
assertEquals(1, registry.getNumberOfRegisteredSynchronizations());
assertEquals(0, synchronization.getBeforeCompletionCount());
assertEquals(0, synchronization.getSuccessfulCompletionCount());
assertEquals(0, synchronization.getFailedCompletionCount());
{
registry.notifySynchronizationsBeforeTransactionCompletion();
assertEquals(1, synchronization.getBeforeCompletionCount());
assertEquals(0, synchronization.getSuccessfulCompletionCount());
assertEquals(0, synchronization.getFailedCompletionCount());
registry.notifySynchronizationsAfterTransactionCompletion(Status.STATUS_COMMITTED);
assertEquals(1, synchronization.getBeforeCompletionCount());
assertEquals(1, synchronization.getSuccessfulCompletionCount());
assertEquals(0, synchronization.getFailedCompletionCount());
}
// afterQuery completion should clear registered synchronizations
assertEquals(0, registry.getNumberOfRegisteredSynchronizations());
// reset the sync
synchronization.reset();
assertEquals(0, synchronization.getBeforeCompletionCount());
assertEquals(0, synchronization.getSuccessfulCompletionCount());
assertEquals(0, synchronization.getFailedCompletionCount());
// re-register it
registry.registerSynchronization(synchronization);
assertEquals(1, registry.getNumberOfRegisteredSynchronizations());
{
registry.notifySynchronizationsAfterTransactionCompletion(Status.STATUS_ROLLEDBACK);
assertEquals(0, synchronization.getBeforeCompletionCount());
assertEquals(0, synchronization.getSuccessfulCompletionCount());
assertEquals(1, synchronization.getFailedCompletionCount());
// afterQuery completion should clear registered synchronizations
assertEquals(0, registry.getNumberOfRegisteredSynchronizations());
}
}
use of org.hibernate.test.resource.common.SynchronizationCollectorImpl 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());
}
Aggregations