use of org.elasticsearch.client.RequestOptions in project hazelcast by hazelcast.
the class ElasticSourcePTest method when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForScrollRequest.
@Test
public void when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForScrollRequest() throws Exception {
SearchHit hit = new SearchHit(0, "id-0", new Text("ignored"), emptyMap(), emptyMap());
hit.sourceRef(new BytesArray(HIT_SOURCE));
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] { hit }, new TotalHits(1, EQUAL_TO), Float.NaN));
SearchResponse response2 = mock(SearchResponse.class);
when(response2.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(1, EQUAL_TO), Float.NaN));
when(mockClient.scroll(any(), any())).thenReturn(response2);
// get different instance than default
TestSupport testSupport = runProcessor(request -> {
Builder builder = RequestOptions.DEFAULT.toBuilder();
builder.addHeader("TestHeader", "value");
return builder.build();
});
testSupport.expectOutput(newArrayList(HIT_SOURCE));
ArgumentCaptor<RequestOptions> captor = forClass(RequestOptions.class);
verify(mockClient).scroll(any(), captor.capture());
RequestOptions capturedOptions = captor.getValue();
assertThat(capturedOptions.getHeaders()).extracting(h -> tuple(h.getName(), h.getValue())).containsExactly(tuple("TestHeader", "value"));
}
use of org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class ElasticsearchClient method withTimeout.
public static RequestOptions withTimeout(RequestOptions requestOptions, Duration timeout) {
final RequestConfig.Builder requestConfigBuilder = (requestOptions == null || requestOptions.getRequestConfig() == null) ? RequestConfig.custom() : RequestConfig.copy(requestOptions.getRequestConfig());
final RequestConfig requestConfigWithTimeout = requestConfigBuilder.setSocketTimeout(Math.toIntExact(timeout.toMilliseconds())).build();
final RequestOptions.Builder requestOptionsBuilder = requestOptions == null ? RequestOptions.DEFAULT.toBuilder() : requestOptions.toBuilder();
return requestOptionsBuilder.setRequestConfig(requestConfigWithTimeout).build();
}
use of org.elasticsearch.client.RequestOptions in project hazelcast by hazelcast.
the class ElasticSourcePTest method when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForSearchRequest.
@Test
public void when_runProcessorWithOptionsFn_then_shouldUseOptionsFnForSearchRequest() throws Exception {
when(response.getHits()).thenReturn(new SearchHits(new SearchHit[] {}, new TotalHits(0, EQUAL_TO), Float.NaN));
// get different instance than default
TestSupport testSupport = runProcessor(request -> {
Builder builder = RequestOptions.DEFAULT.toBuilder();
builder.addHeader("TestHeader", "value");
return builder.build();
});
testSupport.expectOutput(emptyList());
ArgumentCaptor<RequestOptions> captor = forClass(RequestOptions.class);
verify(mockClient).search(any(), captor.capture());
RequestOptions capturedOptions = captor.getValue();
assertThat(capturedOptions.getHeaders()).extracting(h -> tuple(h.getName(), h.getValue())).containsExactly(tuple("TestHeader", "value"));
}
Aggregations