Search in sources :

Example 1 with SearchException

use of org.hibernate.search.util.common.SearchException in project infinispan by infinispan.

the class MassIndexerProgressNotifier method notifyIndexingCompletedSuccessfully.

void notifyIndexingCompletedSuccessfully() {
    monitor.indexingCompleted();
    SearchException entityIndexingException = createEntityIndexingExceptionOrNull();
    if (entityIndexingException != null) {
        throw entityIndexingException;
    }
}
Also used : SearchException(org.hibernate.search.util.common.SearchException)

Example 2 with SearchException

use of org.hibernate.search.util.common.SearchException 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);
    }
}
Also used : EntityReference(org.hibernate.search.mapper.javabean.common.EntityReference) SearchSession(org.hibernate.search.mapper.javabean.session.SearchSession) SearchException(org.hibernate.search.util.common.SearchException) Test(org.junit.Test)

Example 3 with SearchException

use of org.hibernate.search.util.common.SearchException in project hibernate-search by hibernate.

the class SpatialIndexingTest method testNonGeoDistanceSortOnNonSpatialField.

@Test
@TestForIssue(jiraKey = "HSEARCH-1708")
public void testNonGeoDistanceSortOnNonSpatialField() throws Exception {
    double centerLatitude = 24.0d;
    double centerLongitude = 32.0d;
    final QueryBuilder builder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(NonGeoPOI.class).get();
    try {
        builder.sort().byDistance().onField("name").fromLatitude(centerLatitude).andLongitude(centerLongitude).createSort();
        fail("Sorting on a field that it is not a coordinate should fail");
    } catch (SearchException e) {
        assertThat(e).hasMessageContaining("Cannot use 'sort:distance' on field 'name'");
    }
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) QueryBuilder(org.hibernate.search.query.dsl.QueryBuilder) Test(org.junit.Test) TestForIssue(org.hibernate.search.testsupport.TestForIssue)

Example 4 with SearchException

use of org.hibernate.search.util.common.SearchException in project hibernate-search by hibernate.

the class SpatialIndexingTest method testNonGeoDistanceSortOnMissingField.

@Test
@TestForIssue(jiraKey = "HSEARCH-1708")
public void testNonGeoDistanceSortOnMissingField() throws Exception {
    double centerLatitude = 24.0d;
    double centerLongitude = 32.0d;
    final QueryBuilder builder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(NonGeoPOI.class).get();
    try {
        builder.sort().byDistance().onField("location").fromLatitude(centerLatitude).andLongitude(centerLongitude).createSort();
        fail("Sorting on a field not indexed should fail");
    } catch (SearchException e) {
        assertThat(e).hasMessageContaining("Unknown field 'location'");
    }
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) QueryBuilder(org.hibernate.search.query.dsl.QueryBuilder) Test(org.junit.Test) TestForIssue(org.hibernate.search.testsupport.TestForIssue)

Example 5 with SearchException

use of org.hibernate.search.util.common.SearchException in project hibernate-search by hibernate.

the class MassIndexingMonitorIT method simple.

@Test
public void simple() {
    SessionFactory sessionFactory = setup(null);
    with(sessionFactory).runNoTransaction(session -> {
        SearchSession searchSession = Search.session(session);
        MassIndexer indexer = searchSession.massIndexer();
        CompletableFuture<?> indexingFuture = new CompletableFuture<>();
        indexingFuture.completeExceptionally(new SimulatedFailure("Indexing error"));
        // add operations on indexes can follow any random order,
        // since they are executed by different threads
        backendMock.expectWorks(Book.INDEX, DocumentCommitStrategy.NONE, DocumentRefreshStrategy.NONE).add("1", b -> b.field("title", TITLE_1).field("author", AUTHOR_1)).add("3", b -> b.field("title", TITLE_3).field("author", AUTHOR_3)).createAndExecuteFollowingWorks(indexingFuture).add("2", b -> b.field("title", TITLE_2).field("author", AUTHOR_2));
        // purgeAtStart and mergeSegmentsAfterPurge are enabled by default,
        // so we expect 1 purge, 1 mergeSegments and 1 flush calls in this order:
        backendMock.expectIndexScaleWorks(Book.INDEX, session.getTenantIdentifier()).purge().mergeSegments().flush().refresh();
        try {
            indexer.monitor(new StaticCountersMonitor()).startAndWait();
        } catch (SearchException ignored) {
        // Expected, but not relevant to this test
        } catch (InterruptedException e) {
            fail("Unexpected InterruptedException: " + e.getMessage());
        }
    });
    backendMock.verifyExpectationsMet();
    assertThat(staticCounters.get(StaticCountersMonitor.LOADED)).isEqualTo(3);
    assertThat(staticCounters.get(StaticCountersMonitor.BUILT)).isEqualTo(3);
    assertThat(staticCounters.get(StaticCountersMonitor.ADDED)).isEqualTo(2);
    assertThat(staticCounters.get(StaticCountersMonitor.TOTAL)).isEqualTo(3);
    assertThat(staticCounters.get(StaticCountersMonitor.INDEXING_COMPLETED)).isEqualTo(1);
}
Also used : SessionFactory(org.hibernate.SessionFactory) SearchException(org.hibernate.search.util.common.SearchException) StaticCounters(org.hibernate.search.util.impl.test.rule.StaticCounters) Entity(javax.persistence.Entity) Search(org.hibernate.search.mapper.orm.Search) EngineSettings(org.hibernate.search.engine.cfg.EngineSettings) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SessionFactory(org.hibernate.SessionFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test) MassIndexer(org.hibernate.search.mapper.orm.massindexing.MassIndexer) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) Fail.fail(org.assertj.core.api.Fail.fail) MassIndexingMonitor(org.hibernate.search.mapper.pojo.massindexing.MassIndexingMonitor) DocumentCommitStrategy(org.hibernate.search.engine.backend.work.execution.DocumentCommitStrategy) Table(javax.persistence.Table) Rule(org.junit.Rule) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) HibernateOrmMapperSettings(org.hibernate.search.mapper.orm.cfg.HibernateOrmMapperSettings) GenericField(org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField) OrmUtils.with(org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils.with) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) OrmSetupHelper(org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper) DocumentRefreshStrategy(org.hibernate.search.engine.backend.work.execution.DocumentRefreshStrategy) Id(javax.persistence.Id) CompletableFuture(java.util.concurrent.CompletableFuture) MassIndexer(org.hibernate.search.mapper.orm.massindexing.MassIndexer) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) SearchException(org.hibernate.search.util.common.SearchException) Test(org.junit.Test)

Aggregations

SearchException (org.hibernate.search.util.common.SearchException)29 Test (org.junit.Test)20 Indexed (org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed)8 List (java.util.List)5 Transaction (org.hibernate.Transaction)5 FullTextSession (org.hibernate.search.FullTextSession)5 TestForIssue (org.hibernate.search.testsupport.TestForIssue)5 ArrayList (java.util.ArrayList)4 Query (org.apache.lucene.search.Query)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 QueryBuilder (org.hibernate.search.query.dsl.QueryBuilder)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 Entity (javax.persistence.Entity)3 Id (javax.persistence.Id)3 Session (org.hibernate.Session)3 SessionFactory (org.hibernate.SessionFactory)3 BeanHolder (org.hibernate.search.engine.environment.bean.BeanHolder)3 BeanReference (org.hibernate.search.engine.environment.bean.BeanReference)3 BackendMock (org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock)3 StaticCounters (org.hibernate.search.util.impl.test.rule.StaticCounters)3