Search in sources :

Example 1 with TransactionTimeout

use of org.jboss.ejb3.annotation.TransactionTimeout in project wildfly by wildfly.

the class SFSB1 method createEmployeeWaitForTxTimeout.

@TransactionTimeout(value = 1, unit = TimeUnit.SECONDS)
public void createEmployeeWaitForTxTimeout(boolean registerTxSync, String name, String address, int id) {
    LOGGER.trace("org.jboss.as.test.integration.jpa.mockprovider.txtimeout.createEmployeeWaitForTxTimeout " + "entered, will wait for tx time out to occur");
    Employee emp = new Employee();
    emp.setId(id);
    emp.setAddress(address);
    emp.setName(name);
    entityManager.persist(emp);
    boolean done = false;
    if (registerTxSync) {
        transactionSynchronizationRegistry.registerInterposedSynchronization(new Synchronization() {

            @Override
            public void beforeCompletion() {
            }

            @Override
            public void afterCompletion(int status) {
                afterCompletionCalledByTMTimeoutThread = TxUtils.isTransactionManagerTimeoutThread();
            }
        });
    }
    while (!done) {
        try {
            Thread.sleep(250);
            entityManager.find(Employee.class, id);
            int status = transactionSynchronizationRegistry.getTransactionStatus();
            switch(status) {
                case Status.STATUS_COMMITTED:
                    throw new RuntimeException("transaction was committed.");
                case Status.STATUS_ROLLEDBACK:
                    LOGGER.trace("tx timed out and rolled back as expected, success case reached.");
                    done = true;
                    break;
                case Status.STATUS_ACTIVE:
                    LOGGER.trace("tx is still active, sleep for 250ms and check tx status again.");
                    break;
                default:
                    LOGGER.trace("tx status = " + status + ", sleep for 250ms and check tx status again.");
                    break;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
            return;
        }
        LOGGER.trace("org.jboss.as.test.integration.jpa.mockprovider.txtimeout.createEmployeeWaitForTxTimeout waiting for tx to timeout");
    }
}
Also used : Synchronization(javax.transaction.Synchronization) TransactionTimeout(org.jboss.ejb3.annotation.TransactionTimeout)

Example 2 with TransactionTimeout

use of org.jboss.ejb3.annotation.TransactionTimeout in project wildfly by wildfly.

the class StatefulBean method testTimeout.

@TransactionTimeout(value = 1)
public void testTimeout() throws SystemException, RemoteException {
    log.trace("Method stateful #testTimeout called");
    Transaction txn;
    txn = tm.getTransaction();
    TxTestUtil.enlistTestXAResource(txn, checker);
    TxTestUtil.enlistTestXAResource(txn, checker);
    try {
        TxTestUtil.waitForTimeout(tm);
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        throw new RemoteException("Interupted during waiting for transaction timeout", ie);
    }
}
Also used : Transaction(javax.transaction.Transaction) RemoteException(java.rmi.RemoteException) TransactionTimeout(org.jboss.ejb3.annotation.TransactionTimeout)

Example 3 with TransactionTimeout

use of org.jboss.ejb3.annotation.TransactionTimeout in project wildfly by wildfly.

the class StatelessBean method testTimeout.

@TransactionTimeout(value = 1)
public void testTimeout() throws SystemException, RemoteException {
    log.trace("Method stateless #testTimeout called");
    Transaction txn;
    txn = tm.getTransaction();
    TxTestUtil.enlistTestXAResource(txn, checker);
    TxTestUtil.enlistTestXAResource(txn, checker);
    try {
        TxTestUtil.waitForTimeout(tm);
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        throw new RemoteException("Interupted during waiting for transaction timeout", ie);
    }
}
Also used : Transaction(javax.transaction.Transaction) RemoteException(java.rmi.RemoteException) TransactionTimeout(org.jboss.ejb3.annotation.TransactionTimeout)

Aggregations

TransactionTimeout (org.jboss.ejb3.annotation.TransactionTimeout)3 RemoteException (java.rmi.RemoteException)2 Transaction (javax.transaction.Transaction)2 Synchronization (javax.transaction.Synchronization)1