use of org.hibernate.search.mapper.javabean.session.SearchSession in project hibernate-search by hibernate.
the class SearchTimeoutIT method failAfter.
@Test
public void failAfter() {
try (SearchSession session = mapping.createSession()) {
SearchQuery<EntityReference> query = session.search(IndexedEntity.class).selectEntityReference().where(f -> f.matchAll()).failAfter(5L, TimeUnit.SECONDS).toQuery();
SearchException timeoutException = new SearchException("Timed out");
backendMock.expectSearchReferences(Collections.singletonList(INDEX_NAME), // timeout is supposed to be set on the backend
b -> b.failAfter(5L, TimeUnit.SECONDS), StubSearchWorkBehavior.failing(() -> timeoutException));
// Just check that the exception is propagated
assertThatThrownBy(() -> query.fetchAll()).isSameAs(timeoutException);
}
}
use of org.hibernate.search.mapper.javabean.session.SearchSession in project hibernate-search by hibernate.
the class PojoIndexingPlanBaseIT method nullEntity_state.
/**
* Test the state inside indexing plans when the entity is null and must be loaded.
*/
@Test
public void nullEntity_state() {
List<Integer> idsToLoad = new ArrayList<>();
List<IndexedEntity> loadedEntities = new ArrayList<>();
try (SearchSession session = mapping.createSession()) {
IndexedEntity entity;
BackendMock.DocumentWorkCallListContext expectations = backendMock.expectWorks(IndexedEntity.INDEX);
// add then add
entity = new IndexedEntity(1);
session.indexingPlan().add(IndexedEntity.class, entity.id, null);
session.indexingPlan().add(IndexedEntity.class, entity.id, null);
idsToLoad.add(entity.id);
loadedEntities.add(entity);
expectations.add("1", b -> b.field("value", "val1"));
// add then delete
entity = new IndexedEntity(2);
session.indexingPlan().add(IndexedEntity.class, entity.id, null);
session.indexingPlan().delete(IndexedEntity.class, entity.id, null);
// No work expected
// add then update
entity = new IndexedEntity(3);
session.indexingPlan().add(IndexedEntity.class, entity.id, null);
session.indexingPlan().addOrUpdate(IndexedEntity.class, entity.id, null);
idsToLoad.add(entity.id);
loadedEntities.add(entity);
expectations.add("3", b -> b.field("value", "val3"));
// add then update then delete
entity = new IndexedEntity(4);
session.indexingPlan().add(IndexedEntity.class, entity.id, null);
session.indexingPlan().addOrUpdate(IndexedEntity.class, entity.id, null);
session.indexingPlan().delete(IndexedEntity.class, entity.id, null);
// No work expected
// update then update
entity = new IndexedEntity(5);
session.indexingPlan().addOrUpdate(IndexedEntity.class, entity.id, null);
session.indexingPlan().addOrUpdate(IndexedEntity.class, entity.id, null);
idsToLoad.add(entity.id);
loadedEntities.add(entity);
expectations.addOrUpdate("5", b -> b.field("value", "val5"));
// update then delete
entity = new IndexedEntity(6);
session.indexingPlan().addOrUpdate(IndexedEntity.class, entity.id, null);
session.indexingPlan().delete(IndexedEntity.class, entity.id, null);
expectations.delete("6");
// update then delete then add
entity = new IndexedEntity(7);
session.indexingPlan().addOrUpdate(IndexedEntity.class, entity.id, null);
session.indexingPlan().delete(IndexedEntity.class, entity.id, null);
session.indexingPlan().add(IndexedEntity.class, entity.id, null);
idsToLoad.add(entity.id);
loadedEntities.add(entity);
expectations.addOrUpdate("7", b -> b.field("value", "val7"));
// delete then delete
entity = new IndexedEntity(8);
session.indexingPlan().delete(IndexedEntity.class, entity.id, null);
session.indexingPlan().delete(IndexedEntity.class, entity.id, null);
expectations.delete("8");
// delete then add
entity = new IndexedEntity(9);
session.indexingPlan().delete(IndexedEntity.class, entity.id, null);
session.indexingPlan().add(IndexedEntity.class, entity.id, null);
idsToLoad.add(entity.id);
loadedEntities.add(entity);
expectations.addOrUpdate("9", b -> b.field("value", "val9"));
// delete then add then update
entity = new IndexedEntity(10);
session.indexingPlan().delete(IndexedEntity.class, entity.id, null);
session.indexingPlan().add(IndexedEntity.class, entity.id, null);
session.indexingPlan().addOrUpdate(IndexedEntity.class, entity.id, null);
idsToLoad.add(entity.id);
loadedEntities.add(entity);
expectations.addOrUpdate("10", b -> b.field("value", "val10"));
when(loaderMock.load(idsToLoad, null)).thenReturn(loadedEntities);
}
verify(loaderMock).load(any(), any());
}
use of org.hibernate.search.mapper.javabean.session.SearchSession in project hibernate-search by hibernate.
the class AbstractPojoIndexerDeleteNullEntityIT method runtimeException.
@Test
public void runtimeException() {
CompletableFuture<?> futureFromBackend = new CompletableFuture<>();
RuntimeException exception = new RuntimeException();
try (SearchSession session = createSession()) {
SearchIndexer indexer = session.indexer();
expectOperation(futureFromBackend, 1, null, "1");
CompletionStage<?> returnedFuture = scenario().execute(indexer, 1);
backendMock.verifyExpectationsMet();
assertThatFuture(returnedFuture).isPending();
futureFromBackend.completeExceptionally(exception);
assertThatFuture(returnedFuture).isFailed(exception);
}
}
use of org.hibernate.search.mapper.javabean.session.SearchSession in project hibernate-search by hibernate.
the class AbstractPojoIndexerOperationBaseIT method runtimeException.
@Test
public void runtimeException() {
CompletableFuture<?> futureFromBackend = new CompletableFuture<>();
RuntimeException exception = new RuntimeException();
try (SearchSession session = createSession()) {
SearchIndexer indexer = session.indexer();
expectOperation(futureFromBackend, 1, null, "1");
CompletionStage<?> returnedFuture = scenario().execute(indexer, null, IndexedEntity.of(1));
backendMock.verifyExpectationsMet();
assertThatFuture(returnedFuture).isPending();
futureFromBackend.completeExceptionally(exception);
assertThatFuture(returnedFuture).isFailed(exception);
}
}
use of org.hibernate.search.mapper.javabean.session.SearchSession in project hibernate-search by hibernate.
the class AbstractPojoIndexerOperationBaseIT method previouslyIndexedWithMultipleRoutes.
@Test
@TestForIssue(jiraKey = "HSEARCH-3108")
public void previouslyIndexedWithMultipleRoutes() {
assumeImplicitRoutingEnabled();
CompletableFuture<?> futureFromBackend = new CompletableFuture<>();
try (SearchSession session = createSession()) {
SearchIndexer indexer = session.indexer();
MyRoutingBridge.previousValues = Arrays.asList("1", "foo", "3");
expectOperation(futureFromBackend, worksBefore -> {
if (!isAdd()) {
// For operations other than add, expect a delete for every previous route distinct from the current one.
backendMock.expectWorks(IndexedEntity.INDEX, commitStrategy, refreshStrategy).delete(b -> addWorkInfo(b, tenantId, "1", MyRoutingBridge.toRoutingKey(tenantId, 1, "foo")));
backendMock.expectWorks(IndexedEntity.INDEX, commitStrategy, refreshStrategy).delete(b -> addWorkInfo(b, tenantId, "1", MyRoutingBridge.toRoutingKey(tenantId, 1, "3")));
}
}, // And only then, expect the actual operation.
1, null, "1");
CompletionStage<?> returnedFuture = scenario().execute(indexer, null, IndexedEntity.of(1));
backendMock.verifyExpectationsMet();
assertThatFuture(returnedFuture).isPending();
futureFromBackend.complete(null);
assertThatFuture(returnedFuture).isSuccessful();
}
}
Aggregations