use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class GetPostTest method testPost.
@Test
public void testPost() throws Exception {
URI getUri = new URI(SERVICE_URI + "test/setObject");
TestObject obj = new TestObject();
obj.name = "fromClient";
HttpRequest request = HttpRequest.newBuilder().verb(Verb.POST).uri(getUri).entity(obj).build();
HttpResponse response = client.execute(request);
assertEquals(200, response.getStatus());
assertTrue(response.getEntity(TestObject.class).name.equals("fromClient"));
}
use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class GetPostTest method testChunkedEncoding.
@Test
public void testChunkedEncoding() throws Exception {
String obj = "chunked encoded content";
URI postUri = new URI(SERVICE_URI + "test/postStream");
InputStream input = new ByteArrayInputStream(obj.getBytes("UTF-8"));
HttpRequest request = HttpRequest.newBuilder().verb(Verb.POST).uri(postUri).entity(input).build();
HttpResponse response = client.execute(request);
assertEquals(200, response.getStatus());
assertTrue(response.getEntity(String.class).equals(obj));
}
use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class ResponseTimeWeightedRuleTest method testServerWeights.
@Test
public void testServerWeights() {
try {
ConfigurationManager.loadPropertiesFromResources("sample-client.properties");
ConfigurationManager.getConfigInstance().setProperty("sample-client.ribbon.NFLoadBalancerClassName", "com.netflix.loadbalancer.DynamicServerListLoadBalancer");
ConfigurationManager.getConfigInstance().setProperty("sample-client.ribbon.NFLoadBalancerRuleClassName", "com.netflix.loadbalancer.WeightedResponseTimeRule");
// shorter weight adjusting interval
ConfigurationManager.getConfigInstance().setProperty("sample-client.ribbon." + WeightedResponseTimeRule.WEIGHT_TASK_TIMER_INTERVAL_CONFIG_KEY, "5000");
ConfigurationManager.getConfigInstance().setProperty("sample-client.ribbon.InitializeNFLoadBalancer", "true");
RestClient client = (RestClient) ClientFactory.getNamedClient("sample-client");
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
for (int i = 0; i < 20; i++) {
client.executeWithLoadBalancer(request);
}
System.out.println(((AbstractLoadBalancer) client.getLoadBalancer()).getLoadBalancerStats());
// wait for the weights to be adjusted
Thread.sleep(5000);
for (int i = 0; i < 50; i++) {
client.executeWithLoadBalancer(request);
}
System.out.println(((AbstractLoadBalancer) client.getLoadBalancer()).getLoadBalancerStats());
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class RestClientTest method testSecureClient2.
@Test
public void testSecureClient2() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("test3.ribbon." + CommonClientConfigKey.IsSecure, "true");
ConfigurationManager.getConfigInstance().setProperty("test3.ribbon." + CommonClientConfigKey.TrustStore, secureServer.getTrustStore().getAbsolutePath());
ConfigurationManager.getConfigInstance().setProperty("test3.ribbon." + CommonClientConfigKey.TrustStorePassword, SecureGetTest.PASSWORD);
RestClient client = (RestClient) ClientFactory.getNamedClient("test3");
BaseLoadBalancer lb = new BaseLoadBalancer();
Server[] servers = new Server[] { new Server("localhost", secureServer.getServerPort()) };
lb.addServers(Arrays.asList(servers));
client.setLoadBalancer(lb);
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
HttpResponse response = client.executeWithLoadBalancer(request);
assertStatusIsOk(response.getStatus());
assertEquals(secureServer.getServerPath("/"), response.getRequestedURI().toString());
}
use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class RestClientTest method testExecuteWithoutLB.
@Test
public void testExecuteWithoutLB() throws Exception {
RestClient client = (RestClient) ClientFactory.getNamedClient("google");
HttpRequest request = HttpRequest.newBuilder().uri(server.getServerURI()).build();
HttpResponse response = client.executeWithLoadBalancer(request);
assertStatusIsOk(response.getStatus());
response = client.execute(request);
assertStatusIsOk(response.getStatus());
}
Aggregations