use of org.springframework.transaction.TransactionStatus in project uPortal by Jasig.
the class PortalRawEventsAggregatorImplTest method aggregateRawEventsIncompleteByReturn.
@Test
public void aggregateRawEventsIncompleteByReturn() throws Exception {
when(transactionOperations.execute(any(TransactionCallback.class))).then(new Answer<EventProcessingResult>() {
@Override
public EventProcessingResult answer(InvocationOnMock invocation) throws Throwable {
final TransactionStatus status = mock(TransactionStatus.class);
return ((TransactionCallback<EventProcessingResult>) invocation.getArguments()[0]).doInTransaction(status);
}
});
when(clusterLockService.isLockOwner(PortalRawEventsAggregator.AGGREGATION_LOCK_NAME)).thenReturn(true);
when(portalEventDimensionPopulator.isCheckedDimensions()).thenReturn(true);
when(eventAggregationManagementDao.getEventAggregatorStatus(ProcessingType.AGGREGATION, true)).thenReturn(eventAggregatorStatus);
when(portalInfoProvider.getUniqueServerName()).thenReturn("serverName_abcd");
when(eventAggregatorStatus.getLastEventDate()).thenReturn(new DateTime(1325881376117l));
when(portalEventDao.aggregatePortalEvents(any(DateTime.class), any(DateTime.class), (int) any(Integer.TYPE), (Function<PortalEvent, Boolean>) any(Function.class))).then(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
return false;
}
});
final EventProcessingResult result = portalEventAggregator.doAggregateRawEvents();
assertNotNull(result);
assertEquals(0, result.getProcessed());
assertEquals(false, result.isComplete());
}
use of org.springframework.transaction.TransactionStatus in project uPortal by Jasig.
the class PortalRawEventsAggregatorImplTest method aggregateRawEventsIncompleteByProcessCount.
@Test
public void aggregateRawEventsIncompleteByProcessCount() throws Exception {
when(transactionOperations.execute(any(TransactionCallback.class))).then(new Answer<EventProcessingResult>() {
@Override
public EventProcessingResult answer(InvocationOnMock invocation) throws Throwable {
final TransactionStatus status = mock(TransactionStatus.class);
return ((TransactionCallback<EventProcessingResult>) invocation.getArguments()[0]).doInTransaction(status);
}
});
when(clusterLockService.isLockOwner(PortalRawEventsAggregator.AGGREGATION_LOCK_NAME)).thenReturn(true);
when(portalEventDimensionPopulator.isCheckedDimensions()).thenReturn(true);
when(eventAggregationManagementDao.getEventAggregatorStatus(ProcessingType.AGGREGATION, true)).thenReturn(eventAggregatorStatus);
when(portalInfoProvider.getUniqueServerName()).thenReturn("serverName_abcd");
when(eventAggregatorStatus.getLastEventDate()).thenReturn(new DateTime(1325881376117l));
when(portalEventDao.aggregatePortalEvents(any(DateTime.class), any(DateTime.class), (int) any(Integer.TYPE), (Function<PortalEvent, Boolean>) any(Function.class))).then(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
((Function<PortalEvent, Boolean>) invocation.getArguments()[3]).apply(new MockPortalEvent(this, "serverName", "eventSessionId", person));
return false;
}
});
when(eventSessionDao.getEventSession(any(PortalEvent.class))).thenReturn(eventSession);
this.portalEventAggregator.setEventAggregationBatchSize(1);
final EventProcessingResult result = portalEventAggregator.doAggregateRawEvents();
assertNotNull(result);
assertEquals(1, result.getProcessed());
assertEquals(false, result.isComplete());
this.portalEventAggregator.setEventAggregationBatchSize(1000);
}
use of org.springframework.transaction.TransactionStatus in project spring-framework by spring-projects.
the class JpaTransactionManagerTests method testTransactionRollbackWithPropagationSupports.
@Test
public void testTransactionRollbackWithPropagationSupports() {
given(manager.isOpen()).willReturn(true);
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
assertTrue(!TransactionSynchronizationManager.hasResource(factory));
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
tt.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
assertTrue(!TransactionSynchronizationManager.hasResource(factory));
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
assertTrue(!status.isNewTransaction());
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
status.setRollbackOnly();
return null;
}
});
assertTrue(!TransactionSynchronizationManager.hasResource(factory));
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
verify(manager).flush();
verify(manager).close();
}
use of org.springframework.transaction.TransactionStatus in project spring-framework by spring-projects.
the class JpaTransactionManagerTests method testTransactionCommitWithPrebound.
@Test
public void testTransactionCommitWithPrebound() {
given(manager.getTransaction()).willReturn(tx);
final List<String> l = new ArrayList<>();
l.add("test");
assertTrue(!TransactionSynchronizationManager.hasResource(factory));
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
TransactionSynchronizationManager.bindResource(factory, new EntityManagerHolder(manager));
try {
Object result = tt.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.hasResource(factory));
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
return l;
}
});
assertSame(l, result);
assertTrue(TransactionSynchronizationManager.hasResource(factory));
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
} finally {
TransactionSynchronizationManager.unbindResource(factory);
}
verify(tx).begin();
verify(tx).commit();
}
use of org.springframework.transaction.TransactionStatus in project spring-framework by spring-projects.
the class JpaTransactionManagerTests method testTransactionCommitWithDataSource.
@Test
public void testTransactionCommitWithDataSource() throws SQLException {
DataSource ds = mock(DataSource.class);
tm.setDataSource(ds);
given(manager.getTransaction()).willReturn(tx);
final List<String> l = new ArrayList<>();
l.add("test");
assertTrue(!TransactionSynchronizationManager.hasResource(factory));
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
Object result = tt.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.hasResource(factory));
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
return l;
}
});
assertTrue(result == l);
assertTrue(!TransactionSynchronizationManager.hasResource(factory));
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
verify(tx).commit();
verify(manager).flush();
verify(manager).close();
}
Aggregations