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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations