|
39 | 39 | import org.elasticsearch.action.search.SearchRequestBuilder;
|
40 | 40 | import org.elasticsearch.client.Client;
|
41 | 41 | import org.elasticsearch.client.indices.PutIndexTemplateRequest;
|
| 42 | +import org.elasticsearch.common.unit.TimeValue; |
42 | 43 | import org.elasticsearch.common.xcontent.ToXContent;
|
43 | 44 | import org.elasticsearch.common.xcontent.XContentHelper;
|
44 | 45 | import org.elasticsearch.common.xcontent.XContentType;
|
@@ -481,6 +482,29 @@ void shouldSetOpTypeIndexIfSpecified() {
|
481 | 482 |
|
482 | 483 | assertThat(indexRequest.opType()).isEqualTo(DocWriteRequest.OpType.INDEX);
|
483 | 484 | }
|
| 485 | + |
| 486 | + @Test |
| 487 | + @DisplayName("should set timeout to request") |
| 488 | + void shouldSetTimeoutToRequest() { |
| 489 | + Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1)).build(); |
| 490 | + |
| 491 | + SearchRequest searchRequest = requestFactory.searchRequest(query, Person.class, IndexCoordinates.of("persons")); |
| 492 | + |
| 493 | + assertThat(searchRequest.source().timeout()).isEqualTo(TimeValue.timeValueSeconds(1)); |
| 494 | + } |
| 495 | + |
| 496 | + @Test |
| 497 | + @DisplayName("should set timeout to requestbuilder") |
| 498 | + void shouldSetTimeoutToRequestBuilder() { |
| 499 | + when(client.prepareSearch(any())).thenReturn(new SearchRequestBuilder(client, SearchAction.INSTANCE)); |
| 500 | + Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1)).build(); |
| 501 | + |
| 502 | + SearchRequestBuilder searchRequestBuilder = requestFactory.searchRequestBuilder(client, query, Person.class, |
| 503 | + IndexCoordinates.of("persons")); |
| 504 | + |
| 505 | + assertThat(searchRequestBuilder.request().source().timeout()).isEqualTo(TimeValue.timeValueSeconds(1)); |
| 506 | + } |
| 507 | + |
484 | 508 |
|
485 | 509 | private String requestToString(ToXContent request) throws IOException {
|
486 | 510 | return XContentHelper.toXContent(request, XContentType.JSON, true).utf8ToString();
|
|
0 commit comments