use of org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock in project hibernate-search by hibernate.
the class JtaAndSpringOutboxApplicationConfiguration method backendMock.
@Override
public BackendMock backendMock() {
BackendMock backendMock = super.backendMock();
backendMock.indexingWorkExpectations(CoordinationStrategyExpectations.outboxPolling().indexingWorkExpectations);
return backendMock;
}
use of org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock in project hibernate-search by hibernate.
the class SessionProxyIT method useSingleSearchSessionFromMultipleThreads.
@Test
public void useSingleSearchSessionFromMultipleThreads() {
TransactionTemplate template = new TransactionTemplate(transactionManager);
template.execute(status -> {
IndexedEntity entityFromThread1_1 = helperService.simulateSearch(backendMock);
assertThat(entityFromThread1_1).returns(true, helperService.entityManager::contains);
// Same call from the same thread and transaction:
// the same underlying session is used, so we should get the same entity instance
IndexedEntity entityFromThread1_2 = helperService.simulateSearch(backendMock);
assertThat(entityFromThread1_2).returns(entityFromThread1_1.getId(), IndexedEntity::getId);
assertThat(entityFromThread1_2).isSameAs(entityFromThread1_1);
// Same call from another thread: another underlying session is used, so we should a different entity instance
ThreadPoolExecutor executorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(10));
CompletableFuture<IndexedEntity> future = CompletableFuture.supplyAsync(() -> template.execute(status2 -> {
IndexedEntity entityFromThread2 = helperService.simulateSearch(backendMock);
assertThat(entityFromThread2).returns(true, helperService.entityManager::contains);
assertThat(entityFromThread2).returns(entityFromThread1_1.getId(), IndexedEntity::getId);
assertThat(entityFromThread2).isNotSameAs(entityFromThread1_1);
return entityFromThread2;
}), executorService);
IndexedEntity entityFromThread2 = Futures.unwrappedExceptionJoin(future);
assertThat(entityFromThread2).returns(false, helperService.entityManager::contains);
return null;
});
}
use of org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock in project hibernate-search by hibernate.
the class ReusableOrmSetupHolder method methodStatement.
private Statement methodStatement(Statement base, Object testInstance) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
setupSessionFactory(testInstance);
inMethodStatement = true;
base.evaluate();
// we must explicitly force the verify/reset after each test method.
for (BackendMock backendMock : allBackendMocks) {
backendMock.verifyExpectationsMet();
}
} finally {
inMethodStatement = false;
for (BackendMock backendMock : allBackendMocks) {
backendMock.resetExpectations();
}
}
}
};
}
use of org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock in project hibernate-search by hibernate.
the class ReusableOrmSetupHolder method setupSessionFactory.
private void setupSessionFactory(Object testInstance) {
if (!inClassStatement) {
throw new Error("This usage of " + getClass().getSimpleName() + " is invalid and may result" + " in the session factory not being closed." + " Did you use the rule as explained in the javadoc, with both a @ClassRule and a @Rule," + " on two separate fields?");
}
Collection<?> testParams = testParams(testInstance);
if (sessionFactory != null) {
if (testParams.equals(testParamsForSessionFactory)) {
log.infof("Test parameters did not change (%s vs %s). Clearing data and reusing the same session factory.", testParamsForSessionFactory, testParams);
try {
clearAllData(sessionFactory);
} catch (RuntimeException e) {
throw new Error("Failed to clear data before test execution: " + e.getMessage(), e);
}
return;
} else {
log.infof("Test parameters changed (%s vs %s). Closing the current session factory and creating another one.", testParamsForSessionFactory, testParams);
tearDownSessionFactory();
}
}
OrmSetupHelper.SetupContext setupContext = setupHelper.start();
config = new DataClearConfigImpl();
TestCustomSetup customSetup = new TestCustomSetup(testInstance);
customSetup.callSetupMethods(setupContext, config);
sessionFactory = setupContext.setup().unwrap(SessionFactoryImplementor.class);
testParamsForSessionFactory = testParams;
// If any backend expectations where set during setup, verify them immediately.
for (BackendMock backendMock : allBackendMocks) {
backendMock.verifyExpectationsMet();
}
}
Aggregations