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);
}
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());
}
Aggregations