Search in sources :

Example 11 with RewriteClient

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

the class RewriteClientTest 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();
    RewriteClient client = new RewriteClient(serviceName, uri, wrappedClient);
    assertEquals(client.getUri(), uri);
    assertEquals(client.getServiceName(), serviceName);
    assertEquals(client.getWrappedClient(), wrappedClient);
    RestRequest restRequest = new RestRequestBuilder(URI.create("d2://HistoryService/getCube")).build();
    Map<String, String> restWireAttrs = new HashMap<String, String>();
    TestTransportCallback<RestResponse> restCallback = new TestTransportCallback<RestResponse>();
    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());
    // check the rewrite
    assertEquals(wrappedClient.restRequest.getURI(), URI.create("http://test.linkedin.com/test/getCube"));
    assertEquals(wrappedClient.restWireAttrs, restWireAttrs);
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) HashMap(java.util.HashMap) RestResponse(com.linkedin.r2.message.rest.RestResponse) TestClient(com.linkedin.d2.balancer.clients.TrackerClientTest.TestClient) TestTransportCallback(com.linkedin.d2.balancer.clients.TrackerClientTest.TestTransportCallback) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 12 with RewriteClient

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

the class RewriteClientTest method testPathAppend.

@Test
public void testPathAppend() {
    URI uri = URI.create("http://test.linkedin.com:9876/test");
    String serviceName = "HistoryService";
    TestClient wrappedClient = new TestClient();
    RewriteClient client = new RewriteClient(serviceName, uri, wrappedClient);
    assertEquals(client.getUri(), uri);
    assertEquals(client.getServiceName(), serviceName);
    assertEquals(client.getWrappedClient(), wrappedClient);
    RestRequest restRequest;
    Map<String, String> restWireAttrs = new HashMap<String, String>();
    TestTransportCallback<RestResponse> restCallback = new TestTransportCallback<RestResponse>();
    restRequest = new RestRequestBuilder(URI.create("d2://HistoryService")).build();
    client.restRequest(restRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, restRequest, restCallback, "http://test.linkedin.com:9876/test");
    restRequest = new RestRequestBuilder(URI.create("d2://HistoryService/")).build();
    client.restRequest(restRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, restRequest, restCallback, "http://test.linkedin.com:9876/test/");
    restRequest = new RestRequestBuilder(URI.create("d2://HistoryService//")).build();
    client.restRequest(restRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, restRequest, restCallback, "http://test.linkedin.com:9876/test//");
    restRequest = new RestRequestBuilder(URI.create("d2://HistoryService/foo")).build();
    client.restRequest(restRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, restRequest, restCallback, "http://test.linkedin.com:9876/test/foo");
    restRequest = new RestRequestBuilder(URI.create("d2://HistoryService/foo/")).build();
    client.restRequest(restRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, restRequest, restCallback, "http://test.linkedin.com:9876/test/foo/");
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) HashMap(java.util.HashMap) RestResponse(com.linkedin.r2.message.rest.RestResponse) TestClient(com.linkedin.d2.balancer.clients.TrackerClientTest.TestClient) TestTransportCallback(com.linkedin.d2.balancer.clients.TrackerClientTest.TestTransportCallback) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 13 with RewriteClient

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

the class RewriteClientTest method testWithQueryAndFragment.

@Test
public void testWithQueryAndFragment() {
    URI uri = URI.create("http://test.linkedin.com/test");
    String serviceName = "HistoryService";
    TestClient wrappedClient = new TestClient();
    RewriteClient client = new RewriteClient(serviceName, uri, wrappedClient);
    assertEquals(client.getUri(), uri);
    assertEquals(client.getServiceName(), serviceName);
    assertEquals(client.getWrappedClient(), wrappedClient);
    RestRequest restRequest = new RestRequestBuilder(URI.create("d2://HistoryService/getCube?bar=baz#fragId")).build();
    Map<String, String> restWireAttrs = new HashMap<String, String>();
    TestTransportCallback<RestResponse> restCallback = new TestTransportCallback<RestResponse>();
    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) TestClient(com.linkedin.d2.balancer.clients.TrackerClientTest.TestClient) TestTransportCallback(com.linkedin.d2.balancer.clients.TrackerClientTest.TestTransportCallback) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 14 with RewriteClient

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

the class RewriteClientTestStreamRequest method testPathAppend.

@Test
public void testPathAppend() {
    URI uri = URI.create("http://test.linkedin.com:9876/test");
    String serviceName = "HistoryService";
    TestClient wrappedClient = new TestClient();
    RewriteClient client = new RewriteClient(serviceName, uri, wrappedClient);
    assertEquals(client.getUri(), uri);
    assertEquals(client.getServiceName(), serviceName);
    assertEquals(client.getWrappedClient(), wrappedClient);
    StreamRequest streamRequest;
    Map<String, String> restWireAttrs = new HashMap<String, String>();
    TestTransportCallback<StreamResponse> restCallback = new TestTransportCallback<StreamResponse>();
    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) TestClient(com.linkedin.d2.balancer.clients.TrackerClientTest.TestClient) TestTransportCallback(com.linkedin.d2.balancer.clients.TrackerClientTest.TestTransportCallback) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) RequestContext(com.linkedin.r2.message.RequestContext) URI(java.net.URI) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) Test(org.testng.annotations.Test)

Aggregations

URI (java.net.URI)14 RequestContext (com.linkedin.r2.message.RequestContext)13 HashMap (java.util.HashMap)13 Test (org.testng.annotations.Test)11 TestClient (com.linkedin.d2.balancer.clients.TrackerClientTest.TestClient)10 TestTransportCallback (com.linkedin.d2.balancer.clients.TrackerClientTest.TestTransportCallback)10 RestRequest (com.linkedin.r2.message.rest.RestRequest)5 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)5 RestResponse (com.linkedin.r2.message.rest.RestResponse)5 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)5 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)5 RewriteClient (com.linkedin.d2.balancer.clients.RewriteClient)4 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)4 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)4 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)4 FutureCallback (com.linkedin.common.callback.FutureCallback)3 None (com.linkedin.common.util.None)3 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)3 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)3 LoadBalancerStrategyFactory (com.linkedin.d2.balancer.strategies.LoadBalancerStrategyFactory)3