use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext in project spring-cloud-netflix by spring-cloud.
the class OkHttpRibbonCommandFactoryTest method testHystrixDefaultAndRibbonSetting.
@Test
public void testHystrixDefaultAndRibbonSetting() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds", 30);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ConnectTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ReadTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetries", 1);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetriesNextServer", 2);
SpringClientFactory springClientFactory = mock(SpringClientFactory.class);
ZuulProperties zuulProperties = new ZuulProperties();
OkHttpLoadBalancingClient loadBalancingHttpClient = mock(OkHttpLoadBalancingClient.class);
IClientConfig clientConfig = new DefaultClientConfigImpl();
doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(), eq(OkHttpLoadBalancingClient.class));
doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
OkHttpRibbonCommandFactory commandFactory = new OkHttpRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
RibbonCommandContext context = mock(RibbonCommandContext.class);
doReturn("service").when(context).getServiceId();
OkHttpRibbonCommand ribbonCommand = commandFactory.create(context);
assertEquals(30, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext in project spring-cloud-netflix by spring-cloud.
the class OkHttpRibbonCommandFactoryTest method testRibbonTimeoutAndRibbonRetriesDefaultAndDefaultSpaceSetting.
@Test
public void testRibbonTimeoutAndRibbonRetriesDefaultAndDefaultSpaceSetting() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ConnectTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ReadTimeout", 1000);
SpringClientFactory springClientFactory = mock(SpringClientFactory.class);
ZuulProperties zuulProperties = new ZuulProperties();
OkHttpLoadBalancingClient loadBalancingHttpClient = mock(OkHttpLoadBalancingClient.class);
IClientConfig clientConfig = new DefaultClientConfigImpl();
clientConfig.set(IClientConfigKey.Keys.ConnectTimeout, 100);
clientConfig.set(IClientConfigKey.Keys.ReadTimeout, 500);
doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(), eq(OkHttpLoadBalancingClient.class));
doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
OkHttpRibbonCommandFactory commandFactory = new OkHttpRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
RibbonCommandContext context = mock(RibbonCommandContext.class);
doReturn("service").when(context).getServiceId();
OkHttpRibbonCommand ribbonCommand = commandFactory.create(context);
assertEquals(4000, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext in project spring-cloud-netflix by spring-cloud.
the class OkHttpRibbonCommandFactoryTest method testRibbonCommandRetriesAndRibbonCommandTimeoutSetting.
@Test
public void testRibbonCommandRetriesAndRibbonCommandTimeoutSetting() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ConnectTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ReadTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetries", 1);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetriesNextServer", 2);
SpringClientFactory springClientFactory = mock(SpringClientFactory.class);
ZuulProperties zuulProperties = new ZuulProperties();
OkHttpLoadBalancingClient loadBalancingHttpClient = mock(OkHttpLoadBalancingClient.class);
IClientConfig clientConfig = new DefaultClientConfigImpl();
clientConfig.set(IClientConfigKey.Keys.ConnectTimeout, 100);
clientConfig.set(IClientConfigKey.Keys.ReadTimeout, 500);
doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(), eq(OkHttpLoadBalancingClient.class));
doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
OkHttpRibbonCommandFactory commandFactory = new OkHttpRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
RibbonCommandContext context = mock(RibbonCommandContext.class);
doReturn("service").when(context).getServiceId();
OkHttpRibbonCommand ribbonCommand = commandFactory.create(context);
assertEquals(12000, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext in project spring-cloud-netflix by spring-cloud.
the class ZuulApacheHttpClientConfigurationTests method testRibbonLoadBalancingHttpClient.
@Test
public void testRibbonLoadBalancingHttpClient() {
RibbonCommandContext context = new RibbonCommandContext("foo", " GET", "http://localhost", false, new LinkedMultiValueMap<>(), new LinkedMultiValueMap<>(), null, new ArrayList<>(), 0l);
HttpClientRibbonCommand command = httpClientRibbonCommandFactory.create(context);
RibbonLoadBalancingHttpClient ribbonClient = command.getClient();
CloseableHttpClient httpClient = getField(ribbonClient, "delegate");
MockingDetails httpClientDetails = mockingDetails(httpClient);
assertTrue(httpClientDetails.isMock());
}
use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext in project spring-cloud-netflix by spring-cloud.
the class RibbonApacheHttpRequestTests method testNullEntity.
@Test
public void testNullEntity() throws Exception {
String uri = "http://example.com";
LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("my-header", "my-value");
headers.add("content-length", "5192");
LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("myparam", "myparamval");
RibbonApacheHttpRequest httpRequest = new RibbonApacheHttpRequest(new RibbonCommandContext("example", "GET", uri, false, headers, params, null, new ArrayList<RibbonRequestCustomizer>()));
HttpUriRequest request = httpRequest.toRequest(RequestConfig.custom().build());
assertThat("request is wrong type", request, is(not(instanceOf(HttpEntityEnclosingRequest.class))));
assertThat("uri is wrong", request.getURI().toString(), startsWith(uri));
assertThat("my-header is missing", request.getFirstHeader("my-header"), is(notNullValue()));
assertThat("my-header is wrong", request.getFirstHeader("my-header").getValue(), is(equalTo("my-value")));
assertThat("Content-Length is wrong", request.getFirstHeader("content-length").getValue(), is(equalTo("5192")));
assertThat("myparam is missing", request.getURI().getQuery(), is(equalTo("myparam=myparamval")));
}
Aggregations