Search in sources :

Example 1 with TransactionManagementType

use of javax.ejb.TransactionManagementType in project narayana by jbosstm.

the class ConcurrentTransactionalTest method doTest.

/**
 * <p>
 * Following description referees to narayana implementation from version 5.0.0 to 5.0.4.
 * </p>
 * <p>
 * We have a bean - {@link TestTransactionalInvokerBean testTransactionalInvokerBean} -
 * with a method annotated transactional using tx type txType.
 * </p>
 * <p>
 * This method is being called from two threads, where:
 * </p>
 * <ul>
 * <li>
 * Thread 1 is participating in transactionManagementType, therefore it's
 * {@link ServerVMClientUserTransaction#isAvailables} value is true if it's value is
 * {@link TransactionManagementType#BEAN BEAN}.
 * </li>
 * <li>
 * Thread 2 is participating in transaction management type opposite to transactionManagementType,
 * therefore it's {@link ServerVMClientUserTransaction#isAvailables} value is different than for Thread 1.
 * </li>
 * </ul>
 * <p>
 * Both threads call {@link TestTransactionalInvokerBean testTransactionalInvokerBean}'s method with
 * appropriate tx type at the same time.
 * </p>
 * <p>
 * What may happen:
 * </p>
 * <ol>
 * <li>
 * 1. Thread 1 - enters {@link TestTransactionalInvokerBean testTransactionalInvokerBean}'s method.<br/>
 * Interceptor sets previousUserTransactionAvailability.
 * </li>
 * <li>
 * 2. Thread 2 - enters {@link TestTransactionalInvokerBean testTransactionalInvokerBean}'s method.<br/>
 * Interceptor sets previousUserTransactionAvailability to opposite value that it was set in Thread 1.
 * </li>
 * <li>
 * 3. Thread 1 - exits method {@link TestTransactionalInvokerBean testTransactionalInvokerBean}'s and
 * {@link ServerVMClientUserTransaction#isAvailables} thread local value is set to incorrect value.
 * </li>
 * </ol>
 *
 * @param transactionManagementType transaction management type
 * @param txType tx type to which related interceptor test to run.
 */
private void doTest(TransactionManagementType transactionManagementType, TxType txType) {
    CountDownLatch thread1EnterLatch = new CountDownLatch(1);
    CountDownLatch thread2StartLatch = thread1EnterLatch;
    CountDownLatch thread2EnterLatch = new CountDownLatch(1);
    CountDownLatch thread1ExitLatch = thread2EnterLatch;
    CountDownLatch thread2ExitLatch = new CountDownLatch(0);
    boolean startTransaction = txType == TxType.MANDATORY;
    TransactionManagementType otherTransactionManagementType = otherTransactionManagementType(transactionManagementType);
    boolean expectedUserTransactionAvailable = transactionManagementType == TransactionManagementType.BEAN;
    Runnable thread1Runnable = helper.runWithTransactionManagement(transactionManagementType, startTransaction, helper.runAndCheckUserTransactionAvailability(helper.runInTxType(txType, new DeterminingRaceRunnable(thread1EnterLatch, thread1ExitLatch)), expectedUserTransactionAvailable));
    Runnable thread2Runnable = new AwaitAndRun(thread2StartLatch, helper.runWithTransactionManagement(otherTransactionManagementType, startTransaction, helper.runInTxType(txType, new DeterminingRaceRunnable(thread2EnterLatch, thread2ExitLatch))));
    Future<?> thread2Future = executorService.submit(thread2Runnable);
    thread1Runnable.run();
    try {
        thread2Future.get();
    } catch (InterruptedException | ExecutionException e) {
        throw new RuntimeException(e);
    }
}
Also used : TransactionManagementType(javax.ejb.TransactionManagementType) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with TransactionManagementType

use of javax.ejb.TransactionManagementType in project wildfly by wildfly.

the class TransactionManagementMergingProcessor method handleAnnotations.

@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
    final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
    // we only care about annotations on the bean class itself
    if (clazz == null) {
        return;
    }
    ClassAnnotationInformation<TransactionManagement, TransactionManagementType> management = clazz.getAnnotationInformation(TransactionManagement.class);
    if (management == null) {
        return;
    }
    if (!management.getClassLevelAnnotations().isEmpty()) {
        componentConfiguration.setTransactionManagementType(management.getClassLevelAnnotations().get(0));
    }
}
Also used : TransactionManagementType(javax.ejb.TransactionManagementType) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) TransactionManagement(javax.ejb.TransactionManagement)

Example 3 with TransactionManagementType

use of javax.ejb.TransactionManagementType in project narayana by jbosstm.

the class RecursiveTransactionalTest method doTest.

private void doTest(TxType txType) {
    TransactionManagementType oppositeTransactionManagementType = oppositeTransactionManagementType(txType);
    boolean startTransaction = txType == TxType.MANDATORY;
    boolean expectedAvailable = oppositeTransactionManagementType == TransactionManagementType.BEAN;
    Runnable runnable = helper.runWithTransactionManagement(oppositeTransactionManagementType, startTransaction, helper.runAndCheckUserTransactionAvailability(helper.runInTxType(txType, helper.runInTxType(txType, DO_NOTHING)), expectedAvailable));
    runnable.run();
}
Also used : TransactionManagementType(javax.ejb.TransactionManagementType)

Example 4 with TransactionManagementType

use of javax.ejb.TransactionManagementType in project wildfly by wildfly.

the class TransactionManagementMergingProcessor method handleDeploymentDescriptor.

@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
    final EnterpriseBeanMetaData beanMetaData = componentConfiguration.getDescriptorData();
    if (componentConfiguration.isEntity() || beanMetaData == null) {
        return;
    }
    final TransactionManagementType type = componentConfiguration.getDescriptorData().getTransactionType();
    if (type != null) {
        componentConfiguration.setTransactionManagementType(type);
    }
}
Also used : TransactionManagementType(javax.ejb.TransactionManagementType) EnterpriseBeanMetaData(org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData)

Aggregations

TransactionManagementType (javax.ejb.TransactionManagementType)4 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 TransactionManagement (javax.ejb.TransactionManagement)1 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)1 EnterpriseBeanMetaData (org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData)1