Search in sources :

Example 21 with TestTransportCallback

use of com.linkedin.d2.balancer.clients.TrackerClientTest.TestTransportCallback in project rest.li by linkedin.

the class RewriteLoadBalancerClientTest 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);
    RestRequest restRequest = new RestRequestBuilder(URI.create("d2://HistoryService/getCube?bar=baz#fragId")).build();
    Map<String, String> restWireAttrs = new HashMap<>();
    TestTransportCallback<RestResponse> restCallback = new TestTransportCallback<>();
    client.restRequest(restRequest, new RequestContext(), restWireAttrs, restCallback);
    assertFalse(restCallback.response.hasError());
    assertEquals(wrappedClient.restRequest.getHeaders(), restRequest.getHeaders());
    assertEquals(wrappedClient.restRequest.getEntity(), restRequest.getEntity());
    assertEquals(wrappedClient.restRequest.getMethod(), restRequest.getMethod());
    assertEquals(wrappedClient.restRequest.getURI(), URI.create("http://test.linkedin.com/test/getCube?bar=baz#fragId"));
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) HashMap(java.util.HashMap) RestResponse(com.linkedin.r2.message.rest.RestResponse) TestTransportCallback(com.linkedin.d2.balancer.clients.DegraderTrackerClientTest.TestTransportCallback) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 22 with TestTransportCallback

use of com.linkedin.d2.balancer.clients.TrackerClientTest.TestTransportCallback in project rest.li by linkedin.

the class RewriteLoadBalancerClientTest 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);
    RestRequest restRequest = new RestRequestBuilder(URI.create("d2://" + serviceName + path)).build();
    Map<String, String> restWireAttrs = new HashMap<>();
    TestTransportCallback<RestResponse> restCallback = new TestTransportCallback<>();
    client.restRequest(restRequest, new RequestContext(), restWireAttrs, restCallback);
    assertFalse(restCallback.response.hasError());
    assertEquals(wrappedClient.restRequest.getHeaders(), restRequest.getHeaders());
    assertEquals(wrappedClient.restRequest.getEntity(), restRequest.getEntity());
    assertEquals(wrappedClient.restRequest.getMethod(), restRequest.getMethod());
    assertEquals(wrappedClient.restRequest.getURI(), URI.create(hostUri + path));
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) HashMap(java.util.HashMap) RestResponse(com.linkedin.r2.message.rest.RestResponse) TestTransportCallback(com.linkedin.d2.balancer.clients.DegraderTrackerClientTest.TestTransportCallback) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) URI(java.net.URI)

Example 23 with TestTransportCallback

use of com.linkedin.d2.balancer.clients.TrackerClientTest.TestTransportCallback in project rest.li by linkedin.

the class DegraderTrackerClientTest 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 = createDefaultPartitionData(3d);
    DegraderTrackerClient client = new DegraderTrackerClientImpl(uri, partitionDataMap, wrappedClient, clock, null);
    Assert.assertEquals(client.getUri(), uri);
    Double clientWeight = client.getPartitionWeight(DefaultPartitionAccessor.DEFAULT_PARTITION_ID);
    Assert.assertEquals(clientWeight, weight);
    Assert.assertEquals(client.getTransportClient(), wrappedClient);
    StreamRequest streamRequest = new StreamRequestBuilder(uri).build(EntityStreams.emptyStream());
    Map<String, String> restWireAttrs = new HashMap<>();
    TestTransportCallback<StreamResponse> restCallback = new TestTransportCallback<>();
    client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
    Assert.assertFalse(restCallback.response.hasError());
    Assert.assertSame(wrappedClient.streamRequest, streamRequest);
    Assert.assertEquals(wrappedClient.restWireAttrs, restWireAttrs);
}
Also used : HashMap(java.util.HashMap) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) ByteString(com.linkedin.data.ByteString) Clock(com.linkedin.util.clock.Clock) SettableClock(com.linkedin.util.clock.SettableClock) URI(java.net.URI) StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) SettableClock(com.linkedin.util.clock.SettableClock) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test)

Example 24 with TestTransportCallback

use of com.linkedin.d2.balancer.clients.TrackerClientTest.TestTransportCallback in project rest.li by linkedin.

the class RewriteLoadBalancerClientTestStreamRequest method testPathAppend.

@Test
public void testPathAppend() {
    URI uri = URI.create("http://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;
    Map<String, String> restWireAttrs = new HashMap<>();
    TestTransportCallback<StreamResponse> restCallback = new TestTransportCallback<>();
    streamRequest = getRequest("d2://HistoryService");
    client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, streamRequest, restCallback, "http://test.linkedin.com:9876/test");
    streamRequest = getRequest("d2://HistoryService/");
    client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, streamRequest, restCallback, "http://test.linkedin.com:9876/test/");
    streamRequest = getRequest("d2://HistoryService//");
    client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, streamRequest, restCallback, "http://test.linkedin.com:9876/test//");
    streamRequest = getRequest("d2://HistoryService/foo");
    client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, streamRequest, restCallback, "http://test.linkedin.com:9876/test/foo");
    streamRequest = getRequest("d2://HistoryService/foo/");
    client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, streamRequest, restCallback, "http://test.linkedin.com:9876/test/foo/");
}
Also used : HashMap(java.util.HashMap) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) TestTransportCallback(com.linkedin.d2.balancer.clients.DegraderTrackerClientTest.TestTransportCallback) RequestContext(com.linkedin.r2.message.RequestContext) URI(java.net.URI) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) Test(org.testng.annotations.Test)

Aggregations

RequestContext (com.linkedin.r2.message.RequestContext)24 URI (java.net.URI)24 HashMap (java.util.HashMap)24 Test (org.testng.annotations.Test)20 RestRequest (com.linkedin.r2.message.rest.RestRequest)12 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)12 RestResponse (com.linkedin.r2.message.rest.RestResponse)12 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)12 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)12 TestTransportCallback (com.linkedin.d2.balancer.clients.DegraderTrackerClientTest.TestTransportCallback)10 TestClient (com.linkedin.d2.balancer.clients.TrackerClientTest.TestClient)10 TestTransportCallback (com.linkedin.d2.balancer.clients.TrackerClientTest.TestTransportCallback)10 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)4 ByteString (com.linkedin.data.ByteString)4 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)4 Clock (com.linkedin.util.clock.Clock)4 SettableClock (com.linkedin.util.clock.SettableClock)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4