Search in sources :

Example 6 with HttpRequest

use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.

the class RetryTest method testThrottledWithRetrySameServer.

@Test
public void testThrottledWithRetrySameServer() throws Exception {
    URI localUrl = new URI("/status?code=503");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetries, 1).set(CommonClientConfigKey.MaxAutoRetriesNextServer, 0));
        fail("Exception expected");
    } catch (ClientException e) {
    // NOPMD
    }
    assertEquals(2, lb.getLoadBalancerStats().getSingleServerStat(localServer).getSuccessiveConnectionFailureCount());
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) ClientException(com.netflix.client.ClientException) URI(java.net.URI) Test(org.junit.Test)

Example 7 with HttpRequest

use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.

the class RetryTest method testThrottledWithRetryNextServer.

@Test
public void testThrottledWithRetryNextServer() throws Exception {
    int connectionCount = connectionPoolManager.getConnectionsInPool();
    URI localUrl = new URI("/status?code=503");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) {
    // NOPMD
    }
    assertEquals(3, lb.getLoadBalancerStats().getSingleServerStat(localServer).getSuccessiveConnectionFailureCount());
    System.out.println("Initial connections count " + connectionCount);
    System.out.println("Final connections count " + connectionPoolManager.getConnectionsInPool());
    // should be no connection leak        
    assertTrue(connectionPoolManager.getConnectionsInPool() <= connectionCount + 1);
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) ClientException(com.netflix.client.ClientException) URI(java.net.URI) Test(org.junit.Test)

Example 8 with HttpRequest

use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.

the class RetryTest method testRetriesOnPost.

@Test
public void testRetriesOnPost() throws Exception {
    URI localUrl = new URI("/noresponse");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).verb(Verb.POST).setRetriable(true).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) {
    // NOPMD
    }
    ServerStats stats = lb.getLoadBalancerStats().getSingleServerStat(localServer);
    assertEquals(3, stats.getSuccessiveConnectionFailureCount());
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) ServerStats(com.netflix.loadbalancer.ServerStats) ClientException(com.netflix.client.ClientException) URI(java.net.URI) Test(org.junit.Test)

Example 9 with HttpRequest

use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.

the class RetryTest method testReadTimeout.

@Test
public void testReadTimeout() throws Exception {
    URI localUrl = new URI("/noresponse");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) {
    // NOPMD
    }
    assertEquals(3, lb.getLoadBalancerStats().getSingleServerStat(localServer).getSuccessiveConnectionFailureCount());
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) ClientException(com.netflix.client.ClientException) URI(java.net.URI) Test(org.junit.Test)

Example 10 with HttpRequest

use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.

the class SecureAcceptAllGetTest method testPositiveAcceptAllSSLSocketFactory.

@Test
public void testPositiveAcceptAllSSLSocketFactory() throws Exception {
    // test connection succeeds connecting to a random SSL endpoint with allow all SSL factory
    AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
    String name = "GetPostSecureTest" + ".testPositiveAcceptAllSSLSocketFactory";
    String configPrefix = name + "." + "ribbon";
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.CustomSSLSocketFactoryClassName, "com.netflix.http4.ssl.AcceptAllSocketFactory");
    RestClient rc = (RestClient) ClientFactory.getNamedClient(name);
    TEST_SERVER.accept();
    URI getUri = new URI(TEST_SERVICE_URI + "test/");
    HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
    HttpResponse response = rc.execute(request);
    assertEquals(200, response.getStatus());
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) HttpRequest(com.netflix.client.http.HttpRequest) HttpResponse(com.netflix.client.http.HttpResponse) URI(java.net.URI)

Aggregations

HttpRequest (com.netflix.client.http.HttpRequest)36 URI (java.net.URI)28 Test (org.junit.Test)28 HttpResponse (com.netflix.client.http.HttpResponse)21 ClientException (com.netflix.client.ClientException)9 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)5 ServerStats (com.netflix.loadbalancer.ServerStats)4 MockHttpServer (com.netflix.client.testutil.MockHttpServer)3 Server (com.netflix.loadbalancer.Server)3 RestClient (com.netflix.niws.client.http.RestClient)3 InputStream (java.io.InputStream)3 RibbonCommandContext (org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext)3 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)3 IClientConfig (com.netflix.client.config.IClientConfig)2 BaseLoadBalancer (com.netflix.loadbalancer.BaseLoadBalancer)2 ZoneAwareLoadBalancer (com.netflix.loadbalancer.ZoneAwareLoadBalancer)2 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)2 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 MockResponse (com.google.mockwebserver.MockResponse)1