use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext in project spring-cloud-netflix by spring-cloud.
the class OkHttpRibbonCommandFactoryTest method testRibbonAndRibbonRetriesDefaultSetting.
@Test
public void testRibbonAndRibbonRetriesDefaultSetting() throws Exception {
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(1200, 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 testHystrixTimeoutValueCommandSetting.
@Test
public void testHystrixTimeoutValueCommandSetting() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.service.execution.isolation.thread.timeoutInMilliseconds", 50);
RibbonCommandContext context = mock(RibbonCommandContext.class);
doReturn("service").when(context).getServiceId();
OkHttpRibbonCommand ribbonCommand = this.commandFactory.create(context);
assertEquals(50, 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 testRibbonRetriesAndRibbonTimeoutSetting.
@Test
public void testRibbonRetriesAndRibbonTimeoutSetting() throws Exception {
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(3600, 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 testDefaultRibbonSetting.
@Test
public void testDefaultRibbonSetting() throws Exception {
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(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 ZuulOkHttpClientConfigurationTests method testOkHttpLoadBalancingHttpClient.
@Test
public void testOkHttpLoadBalancingHttpClient() {
RibbonCommandContext context = new RibbonCommandContext("foo", " GET", "http://localhost", false, new LinkedMultiValueMap<>(), new LinkedMultiValueMap<>(), null, new ArrayList<>(), 0l);
OkHttpRibbonCommand command = okHttpRibbonCommandFactory.create(context);
OkHttpLoadBalancingClient ribbonClient = command.getClient();
OkHttpClient httpClient = getField(ribbonClient, "delegate");
MockingDetails httpClientDetails = mockingDetails(httpClient);
assertTrue(httpClientDetails.isMock());
}
Aggregations