DATAES-488 - Polishing & Documentation.
Rename VerificationMode -> Verification. Reorder methods in ReactiveElasticsearchClient, add test for DefaultWebClientProvider. Enforce assertions and fix some overall code style issues. Add client reference documentation section.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.client.reactive;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class DefaultWebClientProviderUnitTests {
|
||||
|
||||
@Test // DATAES-488
|
||||
public void shouldCacheClients() {
|
||||
|
||||
DefaultWebClientProvider provider = new DefaultWebClientProvider("http", null);
|
||||
|
||||
WebClient client1 = provider.get(InetSocketAddress.createUnresolved("localhost", 9200));
|
||||
WebClient shouldBeCachedInstanceOfClient1 = provider.get(InetSocketAddress.createUnresolved("localhost", 9200));
|
||||
|
||||
WebClient notClient1ButAnotherInstance = provider.get(InetSocketAddress.createUnresolved("127.0.0.1", 9200));
|
||||
|
||||
assertThat(shouldBeCachedInstanceOfClient1).isSameAs(client1);
|
||||
assertThat(notClient1ButAnotherInstance).isNotSameAs(client1);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.elasticsearch.client.reactive;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.springframework.data.elasticsearch.client.reactive.HostProvider.Verification;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
@@ -25,7 +26,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.elasticsearch.client.ElasticsearchHost;
|
||||
import org.springframework.data.elasticsearch.client.ElasticsearchHost.State;
|
||||
import org.springframework.data.elasticsearch.client.reactive.HostProvider.VerificationMode;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveMockClientTestsUtils.MockDelegatingElasticsearchHostProvider;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveMockClientTestsUtils.MockWebClientProvider.Receive;
|
||||
import org.springframework.web.reactive.function.client.ClientResponse;
|
||||
@@ -92,7 +92,7 @@ public class MultiNodeHostProviderUnitTests {
|
||||
|
||||
provider.clusterInfo().as(StepVerifier::create).expectNextCount(1).verifyComplete();
|
||||
|
||||
provider.getActive(VerificationMode.LAZY).as(StepVerifier::create).expectNext(mock.client(HOST_2)).verifyComplete();
|
||||
provider.getActive(Verification.LAZY).as(StepVerifier::create).expectNext(mock.client(HOST_2)).verifyComplete();
|
||||
|
||||
verify(mock.client(":9201")).head();
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public class MultiNodeHostProviderUnitTests {
|
||||
|
||||
provider.clusterInfo().as(StepVerifier::create).expectNextCount(1).verifyComplete();
|
||||
|
||||
provider.getActive(VerificationMode.ACTIVE).as(StepVerifier::create).expectNext(mock.client(HOST_2))
|
||||
provider.getActive(Verification.ACTIVE).as(StepVerifier::create).expectNext(mock.client(HOST_2))
|
||||
.verifyComplete();
|
||||
|
||||
verify(mock.client(HOST_2), times(2)).head();
|
||||
|
||||
@@ -122,21 +122,21 @@ public class ReactiveMockClientTestsUtils {
|
||||
return delegate.lookupActiveHost();
|
||||
}
|
||||
|
||||
public Mono<InetSocketAddress> lookupActiveHost(VerificationMode verificationMode) {
|
||||
public Mono<InetSocketAddress> lookupActiveHost(Verification verification) {
|
||||
|
||||
if (StringUtils.hasText(activeDefaultHost)) {
|
||||
return Mono.just(getInetSocketAddress(activeDefaultHost));
|
||||
}
|
||||
|
||||
return delegate.lookupActiveHost(verificationMode);
|
||||
return delegate.lookupActiveHost(verification);
|
||||
}
|
||||
|
||||
public Mono<WebClient> getActive() {
|
||||
return delegate.getActive();
|
||||
}
|
||||
|
||||
public Mono<WebClient> getActive(VerificationMode verificationMode) {
|
||||
return delegate.getActive(verificationMode);
|
||||
public Mono<WebClient> getActive(Verification verification) {
|
||||
return delegate.getActive(verification);
|
||||
}
|
||||
|
||||
public WebClient createWebClient(InetSocketAddress endpoint) {
|
||||
|
||||
Reference in New Issue
Block a user