use of com.linkedin.d2.balancer.clients.TrackerClientTest.TestClient in project rest.li by linkedin.
the class RewriteLoadBalancerClientTestStreamRequest method testEscapingHelper.
private void testEscapingHelper(String hostUri, String serviceName, String path) {
URI uri = URI.create(hostUri);
TestClient wrappedClient = new TestClient();
RewriteLoadBalancerClient client = new RewriteLoadBalancerClient(serviceName, uri, wrappedClient);
assertEquals(client.getUri(), uri);
assertEquals(client.getServiceName(), serviceName);
StreamRequest streamRequest = getRequest("d2://" + serviceName + path);
Map<String, String> restWireAttrs = new HashMap<>();
TestTransportCallback<StreamResponse> restCallback = new TestTransportCallback<>();
client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
assertFalse(restCallback.response.hasError());
assertEquals(wrappedClient.streamRequest.getHeaders(), streamRequest.getHeaders());
assertEquals(wrappedClient.streamRequest.getMethod(), streamRequest.getMethod());
assertEquals(wrappedClient.streamRequest.getURI(), URI.create(hostUri + path));
}
use of com.linkedin.d2.balancer.clients.TrackerClientTest.TestClient in project rest.li by linkedin.
the class RewriteLoadBalancerClientTestStreamRequest method testClient.
@Test(groups = { "small", "back-end" })
public void testClient() throws URISyntaxException {
URI uri = URI.create("http://test.linkedin.com/test");
String serviceName = "HistoryService";
TestClient wrappedClient = new TestClient();
RewriteLoadBalancerClient client = new RewriteLoadBalancerClient(serviceName, uri, wrappedClient);
assertEquals(client.getUri(), uri);
assertEquals(client.getServiceName(), serviceName);
StreamRequest streamRequest = new StreamRequestBuilder(URI.create("d2://HistoryService/getCube")).build(EntityStreams.emptyStream());
Map<String, String> restWireAttrs = new HashMap<>();
TestTransportCallback<StreamResponse> restCallback = new TestTransportCallback<>();
client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
assertFalse(restCallback.response.hasError());
assertEquals(wrappedClient.streamRequest.getHeaders(), streamRequest.getHeaders());
assertEquals(wrappedClient.streamRequest.getMethod(), streamRequest.getMethod());
// check the rewrite
assertEquals(wrappedClient.streamRequest.getURI(), URI.create("http://test.linkedin.com/test/getCube"));
assertEquals(wrappedClient.restWireAttrs, restWireAttrs);
}
use of com.linkedin.d2.balancer.clients.TrackerClientTest.TestClient in project rest.li by linkedin.
the class RewriteLoadBalancerClientTestStreamRequest method testWithEverything.
@Test
public void testWithEverything() {
URI uri = URI.create("http://username:password@test.linkedin.com:9876/test");
String serviceName = "HistoryService";
TestClient wrappedClient = new TestClient();
RewriteLoadBalancerClient client = new RewriteLoadBalancerClient(serviceName, uri, wrappedClient);
assertEquals(client.getUri(), uri);
assertEquals(client.getServiceName(), serviceName);
StreamRequest streamRequest = getRequest("d2://HistoryService/getCube?bar=baz#fragId");
Map<String, String> restWireAttrs = new HashMap<>();
TestTransportCallback<StreamResponse> restCallback = new TestTransportCallback<>();
client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
assertFalse(restCallback.response.hasError());
assertEquals(wrappedClient.streamRequest.getHeaders(), streamRequest.getHeaders());
assertEquals(wrappedClient.streamRequest.getMethod(), streamRequest.getMethod());
assertEquals(wrappedClient.streamRequest.getURI(), URI.create("http://username:password@test.linkedin.com:9876/test/getCube?bar=baz#fragId"));
}
use of com.linkedin.d2.balancer.clients.TrackerClientTest.TestClient in project rest.li by linkedin.
the class RewriteLoadBalancerClientTestStreamRequest method testWithQueryAndFragment.
@Test
public void testWithQueryAndFragment() {
URI uri = URI.create("http://test.linkedin.com/test");
String serviceName = "HistoryService";
TestClient wrappedClient = new TestClient();
RewriteLoadBalancerClient client = new RewriteLoadBalancerClient(serviceName, uri, wrappedClient);
assertEquals(client.getUri(), uri);
assertEquals(client.getServiceName(), serviceName);
StreamRequest streamRequest = getRequest("d2://HistoryService/getCube?bar=baz#fragId");
Map<String, String> restWireAttrs = new HashMap<>();
TestTransportCallback<StreamResponse> restCallback = new TestTransportCallback<>();
client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
assertFalse(restCallback.response.hasError());
assertEquals(wrappedClient.streamRequest.getHeaders(), streamRequest.getHeaders());
assertEquals(wrappedClient.streamRequest.getMethod(), streamRequest.getMethod());
assertEquals(wrappedClient.streamRequest.getURI(), URI.create("http://test.linkedin.com/test/getCube?bar=baz#fragId"));
}
use of com.linkedin.d2.balancer.clients.TrackerClientTest.TestClient in project rest.li by linkedin.
the class TrackerClientTest method testClientStreamRequest.
@Test(groups = { "small", "back-end" })
public void testClientStreamRequest() throws URISyntaxException {
URI uri = URI.create("http://test.qa.com:1234/foo");
double weight = 3d;
TestClient wrappedClient = new TestClient(true);
Clock clock = new SettableClock();
Map<Integer, PartitionData> partitionDataMap = new HashMap<Integer, PartitionData>(2);
partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(3d));
TrackerClient client = new TrackerClient(uri, partitionDataMap, wrappedClient, clock, null);
assertEquals(client.getUri(), uri);
Double clientWeight = client.getPartitionWeight(DefaultPartitionAccessor.DEFAULT_PARTITION_ID);
assertEquals(clientWeight, weight);
assertEquals(client.getWrappedClient(), wrappedClient);
StreamRequest streamRequest = new StreamRequestBuilder(uri).build(EntityStreams.emptyStream());
Map<String, String> restWireAttrs = new HashMap<String, String>();
TestTransportCallback<StreamResponse> restCallback = new TestTransportCallback<StreamResponse>();
client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
assertFalse(restCallback.response.hasError());
assertSame(wrappedClient.streamRequest, streamRequest);
assertEquals(wrappedClient.restWireAttrs, restWireAttrs);
}
Aggregations