Search in sources :

Example 1 with XASession

use of org.apache.jackrabbit.api.XASession in project pentaho-platform by pentaho.

the class PentahoTransactionManagerTest method isCreatingTransaction.

@Test
public void isCreatingTransaction() throws Exception {
    PentahoTransactionManager transactionManager = new PentahoTransactionManager();
    SessionFactory sessionFactory = mock(SessionFactory.class);
    XASession xaSession = mock(XASession.class);
    when(xaSession.getXAResource()).thenReturn(mock(XAResource.class));
    transactionManager.setSessionFactory(sessionFactory);
    TransactionDefinition transactionDefinition = mock(TransactionDefinition.class);
    when(transactionDefinition.getIsolationLevel()).thenReturn(-1);
    // All of our assertions must be done while doBegin is being called
    when(sessionFactory.getSession()).then(invocation -> {
        List<Integer> transDefs = Arrays.asList(TransactionDefinition.PROPAGATION_NESTED, TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.PROPAGATION_REQUIRES_NEW);
        for (Integer transDef : transDefs) {
            when(transactionDefinition.getPropagationBehavior()).thenReturn(transDef);
            assertTrue(transactionManager.isCreatingTransaction());
        }
        return xaSession;
    });
    // Calls doBegin
    transactionManager.getTransaction(transactionDefinition);
}
Also used : SessionFactory(org.springframework.extensions.jcr.SessionFactory) TransactionDefinition(org.springframework.transaction.TransactionDefinition) XAResource(javax.transaction.xa.XAResource) XASession(org.apache.jackrabbit.api.XASession) Test(org.junit.Test)

Example 2 with XASession

use of org.apache.jackrabbit.api.XASession in project pentaho-platform by pentaho.

the class PentahoTransactionManagerTest method getTransactionDefinition.

@Test
public void getTransactionDefinition() throws Exception {
    PentahoTransactionManager transactionManager = new PentahoTransactionManager();
    SessionFactory sessionFactory = mock(SessionFactory.class);
    XASession xaSession = mock(XASession.class);
    when(xaSession.getXAResource()).thenReturn(mock(XAResource.class));
    transactionManager.setSessionFactory(sessionFactory);
    TransactionDefinition transactionDefinition = mock(TransactionDefinition.class);
    when(transactionDefinition.getIsolationLevel()).thenReturn(-1);
    // Main assertion. While doBegin is being called, the transactionDefinition can be reached.
    AtomicBoolean wasAvailable = new AtomicBoolean(false);
    when(sessionFactory.getSession()).then(invocation -> {
        assertEquals(transactionDefinition, transactionManager.getTransactionDefinition());
        wasAvailable.set(true);
        return xaSession;
    });
    transactionManager.getTransaction(transactionDefinition);
    assertTrue(wasAvailable.get());
    // after life of doBegin call the definition is not available
    assertNull(transactionManager.getTransactionDefinition());
}
Also used : SessionFactory(org.springframework.extensions.jcr.SessionFactory) TransactionDefinition(org.springframework.transaction.TransactionDefinition) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) XAResource(javax.transaction.xa.XAResource) XASession(org.apache.jackrabbit.api.XASession) Test(org.junit.Test)

Aggregations

XAResource (javax.transaction.xa.XAResource)2 XASession (org.apache.jackrabbit.api.XASession)2 Test (org.junit.Test)2 SessionFactory (org.springframework.extensions.jcr.SessionFactory)2 TransactionDefinition (org.springframework.transaction.TransactionDefinition)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1