use of com.linkedin.d2.balancer.clients.DynamicClient in project rest.li by linkedin.
the class RetryClientTest method testRetryNoAvailableHosts.
@Test
public void testRetryNoAvailableHosts() throws Exception {
SimpleLoadBalancer balancer = prepareLoadBalancer(Arrays.asList("http://test.linkedin.com/retry1", "http://test.linkedin.com/retry2"));
DynamicClient dynamicClient = new DynamicClient(balancer, null);
RetryClient client = new RetryClient(dynamicClient, 3);
URI uri = URI.create("d2://retryService?arg1=empty&arg2=empty");
RestRequest restRequest = new RestRequestBuilder(uri).build();
TrackerClientTest.TestCallback<RestResponse> restCallback = new TrackerClientTest.TestCallback<RestResponse>();
client.restRequest(restRequest, restCallback);
assertNull(restCallback.t);
assertNotNull(restCallback.e);
assertTrue(restCallback.e.toString().contains("retryService is in a bad state"));
}
use of com.linkedin.d2.balancer.clients.DynamicClient in project rest.li by linkedin.
the class RetryClientTest method testRetryOverLimit.
@Test
public void testRetryOverLimit() throws Exception {
SimpleLoadBalancer balancer = prepareLoadBalancer(Arrays.asList("http://test.linkedin.com/retry1", "http://test.linkedin.com/retry2"));
DynamicClient dynamicClient = new DynamicClient(balancer, null);
RetryClient client = new RetryClient(dynamicClient, 1);
URI uri = URI.create("d2://retryService?arg1=empty&arg2=empty");
RestRequest restRequest = new RestRequestBuilder(uri).build();
TrackerClientTest.TestCallback<RestResponse> restCallback = new TrackerClientTest.TestCallback<RestResponse>();
client.restRequest(restRequest, restCallback);
assertNull(restCallback.t);
assertNotNull(restCallback.e);
assertTrue(restCallback.e.getMessage().contains("Data not available"));
}
use of com.linkedin.d2.balancer.clients.DynamicClient in project rest.li by linkedin.
the class LoadBalancerEchoClient method startClient.
public void startClient() throws URISyntaxException, InterruptedException, ExecutionException, IOException, PropertyStoreException {
DynamicClient client = new DynamicClient(getLoadBalancer(_hostPort), null);
for (; ; ) {
int index = 0;
if (_services.length > 1) {
index = _random.nextInt(_services.length);
}
String service = _services[index];
URI uri = URI.create("d2://" + service);
RestRequest req = new RestRequestBuilder(uri).setEntity("hi there".getBytes("UTF-8")).build();
try {
Future<RestResponse> response = client.restRequest(req);
String responseString = response.get().getEntity().asString("UTF-8");
System.err.println(uri + " response: " + responseString);
} catch (ExecutionException e) {
System.err.println("future.get() failed for " + uri + ": " + e);
}
Thread.sleep(_random.nextInt(1000));
}
}
use of com.linkedin.d2.balancer.clients.DynamicClient in project rest.li by linkedin.
the class TestRestLiD2Integration method init.
@BeforeTest
public void init() {
_loadBalancer = MockLBFactory.createLoadBalancer();
_r2Client = new DynamicClient(_loadBalancer, null);
_restClient = new RestClient(_r2Client, "d2://");
}
use of com.linkedin.d2.balancer.clients.DynamicClient in project rest.li by linkedin.
the class D2BaseTest method assertQuorumProcessAllRequests.
public void assertQuorumProcessAllRequests(int num, String jsonConfigData, String zkUriString, LoadBalancerClientCli cli, DynamicClient client, String miscmsg) throws Exception {
Map<String, Object> clustersData = D2ConfigTestUtil.getClusterServiceConfiguration(jsonConfigData);
for (int j = 0; j < num; j++) {
for (String clusterName : clustersData.keySet()) {
String msg = generateMessage(zkUriString);
String response = null;
@SuppressWarnings("unchecked") Map<String, Object> servicesData = (Map<String, Object>) clustersData.get(clusterName);
@SuppressWarnings("unchecked") Map<String, Object> services = (Map<String, Object>) servicesData.get("services");
for (String service : services.keySet()) {
try {
response = cli.sendRequest(client, clusterName, service, msg);
assertTrue(response.contains(LoadBalancerEchoServer.getResponsePostfixString()), "No '" + LoadBalancerEchoServer.getResponsePostfixString() + "' found in response from " + clusterName + "/" + service + ". Response:" + response);
_log.error("Assert pass. Response contains " + LoadBalancerEchoServer.getResponsePostfixString());
} catch (Exception e) {
_log.error("Response for " + clusterName + "/" + service + " failed." + miscmsg + " Error:" + e + "\n", e);
e.printStackTrace();
throw new Exception(e);
}
_log.debug("Response for " + clusterName + "/" + service + ":" + response);
}
}
}
}
Aggregations