DATAES-1003 - Polishing.

This commit is contained in:
Peter-Josef Meisch 2020-12-18 17:36:16 +01:00
parent e950752e79
commit 6fd35b56da
No known key found for this signature in database
GPG Key ID: DE108246970C7708
4 changed files with 27 additions and 19 deletions

View File

@ -1174,7 +1174,7 @@ class RequestFactory {
}
TimeValue timeout = query.getTimeout();
if (timeout !=null) {
if (timeout != null) {
sourceBuilder.timeout(timeout);
}
@ -1254,7 +1254,7 @@ class RequestFactory {
}
TimeValue timeout = query.getTimeout();
if (timeout !=null) {
if (timeout != null) {
searchRequestBuilder.setTimeout(timeout);
}

View File

@ -261,7 +261,13 @@ abstract class AbstractQuery implements Query {
return timeout;
}
public void setTimeout(TimeValue timeout) {
/**
* set the query timeout
*
* @param timeout
* @since 4.2
*/
public void setTimeout(@Nullable TimeValue timeout) {
this.timeout = timeout;
}
}

View File

@ -278,9 +278,10 @@ public interface Query {
}
/**
* Get timeout
* Get the query timeout.
*
* @return null if not set
* @since 4.2
*/
@Nullable
TimeValue getTimeout();

View File

@ -483,21 +483,23 @@ class RequestFactoryTests {
assertThat(indexRequest.opType()).isEqualTo(DocWriteRequest.OpType.INDEX);
}
@Test
@Test // DATAES-1003
@DisplayName("should set timeout to request")
void shouldSetTimeoutToRequest() {
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1)).build();
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1))
.build();
SearchRequest searchRequest = requestFactory.searchRequest(query, Person.class, IndexCoordinates.of("persons"));
assertThat(searchRequest.source().timeout()).isEqualTo(TimeValue.timeValueSeconds(1));
}
@Test
@Test // DATAES-1003
@DisplayName("should set timeout to requestbuilder")
void shouldSetTimeoutToRequestBuilder() {
when(client.prepareSearch(any())).thenReturn(new SearchRequestBuilder(client, SearchAction.INSTANCE));
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1)).build();
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1))
.build();
SearchRequestBuilder searchRequestBuilder = requestFactory.searchRequestBuilder(client, query, Person.class,
IndexCoordinates.of("persons"));
@ -505,7 +507,6 @@ class RequestFactoryTests {
assertThat(searchRequestBuilder.request().source().timeout()).isEqualTo(TimeValue.timeValueSeconds(1));
}
private String requestToString(ToXContent request) throws IOException {
return XContentHelper.toXContent(request, XContentType.JSON, true).utf8ToString();
}