public void populateDatabase() { if (m_populateInSeparateTransaction) { m_transOperation.execute( new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(final TransactionStatus status) { doPopulateDatabase(); } }); } else { doPopulateDatabase(); } }
@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); }
/** * Factory method for creating a {@link CriteriaQuery} employing standards and best practices in * general use within the portal. Query objects returned from this method should normally be * passed to {@link createCachedQuery}; this step is important for the sake of scalability. */ protected final <T> CriteriaQuery<T> createCriteriaQuery( Function<CriteriaBuilder, CriteriaQuery<T>> builder) { final EntityManager entityManager = this.getEntityManager(); final EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory(); final CriteriaBuilder criteriaBuilder = entityManagerFactory.getCriteriaBuilder(); final CriteriaQuery<T> criteriaQuery = builder.apply(criteriaBuilder); // Do in TX so the EM gets closed correctly final TransactionOperations transactionOperations = this.getTransactionOperations(); transactionOperations.execute( new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { entityManager.createQuery( criteriaQuery); // pre-compile critera query to avoid race conditions when setting // aliases } }); return criteriaQuery; }