use of org.springframework.data.elasticsearch.client.reactive.ReactiveMockClientTestsUtils.MockWebClientProvider.Receive in project spring-data-elasticsearch by spring-projects.
the class MultiNodeHostProviderUnitTests method triesDeadHostsIfNoActiveFound.
// DATAES-488
@Test
public void triesDeadHostsIfNoActiveFound() {
multiNodeDelegatingHostProvider.when(HOST_1).receive(Receive::error);
multiNodeDelegatingHostProvider.when(HOST_2).get(requestHeadersUriSpec -> {
ClientResponse response1 = mock(ClientResponse.class);
when(response1.releaseBody()).thenReturn(Mono.empty());
Receive.error(response1);
ClientResponse response2 = mock(ClientResponse.class);
when(response2.releaseBody()).thenReturn(Mono.empty());
Receive.ok(response2);
//
when(requestHeadersUriSpec.exchangeToMono(any())).thenAnswer(//
invocation -> getAnswer(invocation, response1)).thenAnswer(invocation -> getAnswer(invocation, response2));
});
multiNodeDelegatingHostProvider.when(HOST_3).receive(Receive::error);
delegateHostProvider.clusterInfo().as(StepVerifier::create).expectNextCount(1).verifyComplete();
assertThat(delegateHostProvider.getCachedHostState()).extracting(ElasticsearchHost::getState).containsExactly(State.OFFLINE, State.OFFLINE, State.OFFLINE);
delegateHostProvider.getActive().as(StepVerifier::create).expectNext(multiNodeDelegatingHostProvider.client(HOST_2)).verifyComplete();
verify(multiNodeDelegatingHostProvider.client(HOST_2), times(2)).head();
}
use of org.springframework.data.elasticsearch.client.reactive.ReactiveMockClientTestsUtils.MockWebClientProvider.Receive in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchClientUnitTests method pingShouldHitMainEndpoint.
// --> PING
@Test
public void pingShouldHitMainEndpoint() {
//
hostProvider.when(HOST).receive(Receive::ok);
//
client.ping().then().as(//
StepVerifier::create).verifyComplete();
URI uri = hostProvider.when(HOST).captureUri();
assertThat(uri.getRawPath()).isEqualTo("/");
}
use of org.springframework.data.elasticsearch.client.reactive.ReactiveMockClientTestsUtils.MockWebClientProvider.Receive in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchClientUnitTests method searchShouldReturnMultipleResultsCorrectly.
// DATAES-488
@Test
public void searchShouldReturnMultipleResultsCorrectly() {
//
hostProvider.when(HOST).receive(//
Receive::json).body(fromPath("search-ok-multiple-hits"));
//
client.search(new SearchRequest("twitter")).as(//
StepVerifier::create).consumeNextWith(hit -> {
assertThat(hit.getId()).isEqualTo("2");
assertThat(hit.getIndex()).isEqualTo("twitter");
//
assertThat(hit.getSourceAsMap()).containsEntry("user", //
"kimchy").containsEntry("message", //
"Another tweet, will it be indexed?").containsKey("post_date");
}).consumeNextWith(hit -> {
assertThat(hit.getId()).isEqualTo("1");
assertThat(hit.getIndex()).isEqualTo("twitter");
//
assertThat(hit.getSourceAsMap()).containsEntry("user", //
"kimchy").containsEntry("message", //
"Trying out Elasticsearch, so far so good?").containsKey("post_date");
}).verifyComplete();
}
use of org.springframework.data.elasticsearch.client.reactive.ReactiveMockClientTestsUtils.MockWebClientProvider.Receive in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchClientUnitTests method aggregateShouldReturnMultipleResultsCorrectly.
// DATAES-567
@Test
public void aggregateShouldReturnMultipleResultsCorrectly() {
//
hostProvider.when(HOST).receive(//
Receive::json).body(fromPath("aggregate-ok-multiple-results"));
//
client.aggregate(new SearchRequest("twitter")).as(//
StepVerifier::create).consumeNextWith(aggregation -> {
assertThat(aggregation.getName()).isEqualTo("users");
assertThat(aggregation instanceof ParsedStringTerms);
ParsedStringTerms parsedStringTerms = (ParsedStringTerms) aggregation;
assertThat(parsedStringTerms.getBuckets().size()).isEqualTo(2);
assertThat(parsedStringTerms.getBucketByKey("kimchy").getDocCount()).isEqualTo(2);
assertThat(parsedStringTerms.getBucketByKey("elastic").getDocCount()).isEqualTo(1);
}).consumeNextWith(aggregation -> {
assertThat(aggregation.getName()).isEqualTo("max_post_date");
assertThat(aggregation instanceof ParsedMax);
ParsedMax parsedMax = (ParsedMax) aggregation;
assertThat(Instant.ofEpochMilli((long) parsedMax.getValue())).isEqualTo(Instant.parse("2010-01-15T01:46:38Z"));
}).verifyComplete();
}
Aggregations