Browse Source

Cleanup and code review fixes.

pull/6/head
Ryan Baxter 7 years ago
parent
commit
78ba3c5394
  1. 14
      docs/src/main/asciidoc/spring-cloud-netflix.adoc
  2. 9
      spring-cloud-netflix-core/src/test/java/OkHttpClientConfigurationTests.java
  3. 10
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ApacheHttpClientConfigurationTests.java
  4. 2
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/FeignHttpClientUrlTests.java
  5. 13
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/CustomHostRoutingFilterTests.java
  6. 2
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/okhttp/OkHttpRibbonRetryIntegrationTests.java

14
docs/src/main/asciidoc/spring-cloud-netflix.adoc

@ -11,9 +11,6 @@ @@ -11,9 +11,6 @@
include::intro.adoc[]
== HTTP Clients
== Service Discovery: Eureka Clients
@ -2511,3 +2508,14 @@ method to determine whether you want to retry a request given the status code. @@ -2511,3 +2508,14 @@ method to determine whether you want to retry a request given the status code.
You can turn off Zuul's retry functionality by setting `zuul.retryable` to `false`. You
can also disable retry functionality on route by route basis by setting
`zuul.routes.routename.retryable` to `false`.
== HTTP Clients
Spring Cloud Netflix will automatically create the HTTP client used by Ribbon, Feign, and
Zuul for you. However you can also provide your own HTTP clients customized how you please
yourself. To do this you can either create a bean of type `ClosableHttpClient` if you
are using the Apache Http Cient, or `OkHttpClient` if you are using OK HTTP.
NOTE: When you create your own HTTP client you are also responsible for implementing
the correct connection management strategies for these clients. Doing this improperly
can result in resource management issues.

9
spring-cloud-netflix-core/src/test/java/OkHttpClientConfigurationTests.java

@ -25,6 +25,7 @@ import java.util.ArrayList; @@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockingDetails;
@ -79,10 +80,10 @@ public class OkHttpClientConfigurationTests { @@ -79,10 +80,10 @@ public class OkHttpClientConfigurationTests {
@Test
public void testFactories() {
assertTrue(OkHttpClientConnectionPoolFactory.class.isInstance(connectionPoolFactory));
assertTrue(OkHttpClientConfigurationTestApp.MyOkHttpClientConnectionPoolFactory.class.isInstance(connectionPoolFactory));
assertTrue(OkHttpClientFactory.class.isInstance(okHttpClientFactory));
assertTrue(OkHttpClientConfigurationTestApp.MyOkHttpClientFactory.class.isInstance(okHttpClientFactory));
Assertions.assertThat(connectionPoolFactory).isInstanceOf(OkHttpClientConnectionPoolFactory.class);
Assertions.assertThat(connectionPoolFactory).isInstanceOf(OkHttpClientConfigurationTestApp.MyOkHttpClientConnectionPoolFactory.class);
Assertions.assertThat(okHttpClientFactory).isInstanceOf(OkHttpClientFactory.class);
Assertions.assertThat(okHttpClientFactory).isInstanceOf(OkHttpClientConfigurationTestApp.MyOkHttpClientFactory.class);
}
@Test

10
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ApacheHttpClientConfigurationTests.java

@ -28,7 +28,6 @@ import java.util.concurrent.TimeUnit; @@ -28,7 +28,6 @@ import java.util.concurrent.TimeUnit;
import org.apache.http.Header;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.config.RegistryBuilder;
@ -37,6 +36,7 @@ import org.apache.http.impl.client.CloseableHttpClient; @@ -37,6 +36,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicHeader;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockingDetails;
@ -98,10 +98,10 @@ public class ApacheHttpClientConfigurationTests { @@ -98,10 +98,10 @@ public class ApacheHttpClientConfigurationTests {
@Test
public void testFactories() {
assertTrue(ApacheHttpClientConnectionManagerFactory.class.isInstance(connectionManagerFactory));
assertTrue(ApacheHttpClientConfigurationTestApp.MyApacheHttpClientConnectionManagerFactory.class.isInstance(connectionManagerFactory));
assertTrue(ApacheHttpClientFactory.class.isInstance(httpClientFactory));
assertTrue(ApacheHttpClientConfigurationTestApp.MyApacheHttpClientFactory.class.isInstance(httpClientFactory));
Assertions.assertThat(connectionManagerFactory).isInstanceOf(ApacheHttpClientConnectionManagerFactory.class);
Assertions.assertThat(connectionManagerFactory).isInstanceOf(ApacheHttpClientConfigurationTestApp.MyApacheHttpClientConnectionManagerFactory.class);
Assertions.assertThat(httpClientFactory).isInstanceOf(ApacheHttpClientFactory.class);
Assertions.assertThat(httpClientFactory).isInstanceOf(ApacheHttpClientConfigurationTestApp.MyApacheHttpClientFactory.class);
}
@Test

2
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/FeignHttpClientUrlTests.java

@ -58,7 +58,7 @@ import lombok.NoArgsConstructor; @@ -58,7 +58,7 @@ import lombok.NoArgsConstructor;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = FeignHttpClientUrlTests.TestConfig.class, webEnvironment = WebEnvironment.DEFINED_PORT, value = {
"spring.application.name=feignclienturltest", "feign.hystrix.enabled=false",
"spring.cloud.httpclientfactories.ok.enabled=false" })
"feign.okhttp.enabled=false" })
@DirtiesContext
public class FeignHttpClientUrlTests {

13
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/CustomHostRoutingFilterTests.java

@ -254,19 +254,6 @@ class SampleCustomZuulProxyApplication { @@ -254,19 +254,6 @@ class SampleCustomZuulProxyApplication {
private class CustomApacheHttpClientFactory extends DefaultApacheHttpClientFactory {
//@Override
//public HttpClientBuilder createBuilder() {
// return HttpClients.custom()
// .setDefaultCookieStore(new BasicCookieStore())
// .setDefaultRequestConfig(RequestConfig.custom()
// .setCookieSpec(CookieSpecs.DEFAULT).build());
//}public CloseableHttpClient createClient(RequestConfig requestConfig, HttpClientConnectionManager connectionManager) {
// return HttpClients.custom().setConnectionManager(connectionManager)
// .setDefaultCookieStore(new BasicCookieStore())
// .setDefaultRequestConfig(RequestConfig.custom()
// .setCookieSpec(CookieSpecs.DEFAULT).build())
// .build();
// }
}
}

2
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/okhttp/OkHttpRibbonRetryIntegrationTests.java

@ -30,7 +30,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -30,7 +30,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = RibbonRetryIntegrationTestBase.RetryableTestConfig.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = {
"zuul.retryable: false", /* Disable retry by default, have each route enable it */
"ribbon.okhttp.enabled",
"ribbon.okhttp.enabled: true",
"hystrix.command.default.execution.timeout.enabled: false", /* Disable hystrix so its timeout doesnt get in the way */
"ribbon.ReadTimeout: 1000", /* Make sure ribbon will timeout before the thread is done sleeping */
"zuul.routes.retryable: /retryable/**",

Loading…
Cancel
Save