Skip to content

Commit 092a2f9

Browse files
fax4everyrodiere
authored andcommitted
HSEARCH-3352 Test timeout option on mapper pojo
This test is not very significant, since the option is handled on the backends.
1 parent d5fbd84 commit 092a2f9

File tree

1 file changed

+85
-0
lines changed
  • integrationtest/mapper/pojo-base/src/test/java/org/hibernate/search/integrationtest/mapper/pojo/timeout

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Hibernate Search, full-text search for your domain model
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.search.integrationtest.mapper.pojo.timeout;
8+
9+
import java.lang.invoke.MethodHandles;
10+
import java.util.Collections;
11+
import java.util.concurrent.TimeUnit;
12+
13+
import org.hibernate.search.engine.search.query.SearchQuery;
14+
import org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper;
15+
import org.hibernate.search.mapper.javabean.common.EntityReference;
16+
import org.hibernate.search.mapper.javabean.mapping.SearchMapping;
17+
import org.hibernate.search.mapper.javabean.session.SearchSession;
18+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId;
19+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
20+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField;
21+
import org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock;
22+
import org.hibernate.search.util.impl.integrationtest.common.rule.StubSearchWorkBehavior;
23+
24+
import org.junit.Before;
25+
import org.junit.Rule;
26+
import org.junit.Test;
27+
28+
import org.assertj.core.api.Assertions;
29+
30+
public class SearchTimeoutIT {
31+
32+
private static final String INDEX_NAME = "IndexName";
33+
34+
@Rule
35+
public BackendMock backendMock = new BackendMock( "stubBackend" );
36+
37+
@Rule
38+
public JavaBeanMappingSetupHelper setupHelper = JavaBeanMappingSetupHelper.withBackendMock( MethodHandles.lookup(), backendMock );
39+
40+
private SearchMapping mapping;
41+
42+
@Before
43+
public void setup() {
44+
backendMock.expectSchema( INDEX_NAME, b -> b.field( "keyword", String.class ) );
45+
mapping = setupHelper.start().setup( IndexedEntity.class );
46+
backendMock.verifyExpectationsMet();
47+
}
48+
49+
@Test
50+
public void timeoutOption() {
51+
try ( SearchSession session = mapping.createSession() ) {
52+
SearchQuery<EntityReference> query = session.search( IndexedEntity.class )
53+
.asEntityReference()
54+
.predicate( f -> f.matchAll() )
55+
// define a timeout
56+
.timeout( 5L, TimeUnit.SECONDS )
57+
.toQuery();
58+
59+
backendMock.expectSearchReferences( Collections.singletonList( INDEX_NAME ),
60+
// timeout is supposed to be set on the backend
61+
b -> b.timeout( 5L, TimeUnit.SECONDS ),
62+
StubSearchWorkBehavior.of( 0L, Collections.emptyList() )
63+
);
64+
65+
Assertions.assertThat( query.fetchAll().getHits() ).isEmpty();
66+
}
67+
}
68+
69+
@Indexed(index = INDEX_NAME)
70+
public static final class IndexedEntity {
71+
72+
private Integer id;
73+
private String keyword;
74+
75+
@DocumentId
76+
public Integer getId() {
77+
return id;
78+
}
79+
80+
@KeywordField
81+
public String getKeyword() {
82+
return keyword;
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)