Search in sources :

Example 6 with OkHttpLoadBalancingClient

use of org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient 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());
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) OkHttpLoadBalancingClient(org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient) FallbackProvider(org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider) RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) IClientConfig(com.netflix.client.config.IClientConfig) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 7 with OkHttpLoadBalancingClient

use of org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient 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());
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) OkHttpLoadBalancingClient(org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient) FallbackProvider(org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider) RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) IClientConfig(com.netflix.client.config.IClientConfig) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 8 with OkHttpLoadBalancingClient

use of org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient 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());
}
Also used : OkHttpClient(okhttp3.OkHttpClient) OkHttpLoadBalancingClient(org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient) RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) OkHttpRibbonCommand(org.springframework.cloud.netflix.zuul.filters.route.okhttp.OkHttpRibbonCommand) MockingDetails(org.mockito.MockingDetails) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with OkHttpLoadBalancingClient

use of org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient in project spring-cloud-netflix by spring-cloud.

the class OkHttpRibbonCommandFactory method create.

@Override
public OkHttpRibbonCommand create(final RibbonCommandContext context) {
    final String serviceId = context.getServiceId();
    FallbackProvider fallbackProvider = getFallbackProvider(serviceId);
    final OkHttpLoadBalancingClient client = this.clientFactory.getClient(serviceId, OkHttpLoadBalancingClient.class);
    client.setLoadBalancer(this.clientFactory.getLoadBalancer(serviceId));
    return new OkHttpRibbonCommand(serviceId, client, context, zuulProperties, fallbackProvider, clientFactory.getClientConfig(serviceId));
}
Also used : OkHttpLoadBalancingClient(org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient) FallbackProvider(org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider)

Example 10 with OkHttpLoadBalancingClient

use of org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient in project spring-cloud-netflix by spring-cloud.

the class OkHttpRibbonCommandFactoryTest method testRibbonCommandRetriesAndRibbonCommandTimeoutPartOfSetting.

@Test
public void testRibbonCommandRetriesAndRibbonCommandTimeoutPartOfSetting() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ConnectTimeout", 1000);
    ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetries", 1);
    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(6000, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) OkHttpLoadBalancingClient(org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient) FallbackProvider(org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider) RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) IClientConfig(com.netflix.client.config.IClientConfig) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Aggregations

OkHttpLoadBalancingClient (org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient)14 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)11 IClientConfig (com.netflix.client.config.IClientConfig)11 Test (org.junit.Test)11 SpringClientFactory (org.springframework.cloud.netflix.ribbon.SpringClientFactory)11 RibbonCommandContext (org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext)11 ZuulProperties (org.springframework.cloud.netflix.zuul.filters.ZuulProperties)11 FallbackProvider (org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider)11 AbstractLoadBalancerAwareClient (com.netflix.client.AbstractLoadBalancerAwareClient)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 OkHttpClient (okhttp3.OkHttpClient)1 Before (org.junit.Before)1 MockingDetails (org.mockito.MockingDetails)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 OverrideRestClient (org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration.OverrideRestClient)1 RibbonLoadBalancingHttpClient (org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient)1 OkHttpRibbonCommand (org.springframework.cloud.netflix.zuul.filters.route.okhttp.OkHttpRibbonCommand)1