Examples of TransportClientAdapter


Examples of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter

   */
  public static void main(String[] args) throws Exception
  {
    // Create an HttpClient and wrap it in an abstraction layer
    final HttpClientFactory http = new HttpClientFactory();
    final Client r2Client = new TransportClientAdapter(
                                      http.getClient(Collections.<String, String>emptyMap()));

    // Create a RestClient to talk to localhost:8080
    RestClient restClient = new RestClient(r2Client, "http://localhost:8080/");

View Full Code Here

Examples of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter

  @Test
  public void testClient() throws Exception
  {
    final TransportClient transportClient = _clientFactory.getClient(new HashMap<String, String>());
    final Client client = new TransportClientAdapter(transportClient);

    RestRequestBuilder rb = new RestRequestBuilder(_testServer.getRequestURI());
    rb.setMethod("GET");
    RestRequest request = rb.build();
    Future<RestResponse> f = client.restRequest(request);

    // This will block
    RestResponse response = f.get();
    final ByteString entity = response.getEntity();
    if (entity != null) {
      System.out.println(entity.asString("UTF-8"));
    } else {
      System.out.println("NOTHING!");
    }

    assertEquals(response.getStatus(), 200);

    final FutureCallback<None> callback = new FutureCallback<None>();
    client.shutdown(callback);
    callback.get();
  }
View Full Code Here

Examples of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter

  {
    final Integer REQUEST_TIMEOUT = 1000;
    final TransportClient transportClient =
        _clientFactory.getClient(Collections.singletonMap(HttpClientFactory.HTTP_REQUEST_TIMEOUT,
                                                          Integer.toString(REQUEST_TIMEOUT)));
    final Client client = new TransportClientAdapter(transportClient);

    RestRequestBuilder rb = new RestRequestBuilder(_testServer.getRequestURI());
    rb.setMethod("GET");
    RestRequest request = rb.build();

    final RequestContext context = new RequestContext();
    Future<RestResponse> f = client.restRequest(request, context);
    Future<RestResponse> f2 = client.restRequest(request, context);

    // This will block
    RestResponse response = f.get(REQUEST_TIMEOUT, TimeUnit.MILLISECONDS);
    assertEquals(response.getStatus(), 200);

    response = f2.get(REQUEST_TIMEOUT, TimeUnit.MILLISECONDS);
    assertEquals(response.getStatus(), 200);

    final Integer iterations = 5;
    final CountDownLatch latch = new CountDownLatch(iterations);
    //Test that sending multiple requests with the same request context works correctly, without
    //modifying the original request context.
    for (int i=0; i<iterations; ++i)
    {
      client.restRequest(request, context, new Callback<RestResponse>()
      {
        @Override
        public void onError(Throwable e)
        {
          Assert.fail("Expected success, received: " + e);
          latch.countDown();
        }

        @Override
        public void onSuccess(RestResponse result)
        {
          Assert.assertEquals(result.getStatus(), 200);
          latch.countDown();
        }
      });
    }
    latch.await(REQUEST_TIMEOUT, TimeUnit.MILLISECONDS);

    Assert.assertTrue(context.getLocalAttrs().isEmpty());

    final FutureCallback<None> callback = new FutureCallback<None>();
    client.shutdown(callback);
    callback.get();
  }
View Full Code Here

Examples of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter

    // Specify the get timeout; we know the max rate will be half the get timeout
    final TransportClient transportClient =
        new HttpClientFactory().getClient(Collections.singletonMap(HttpClientFactory.HTTP_REQUEST_TIMEOUT,
                                                                   Integer.toString(REQUEST_TIMEOUT)));
    final Client client = new TransportClientAdapter(transportClient);

    final ServerSocket ss = new ServerSocket();
    ss.bind(null);
    final CountDownLatch latch = new CountDownLatch(N + WARM_UP);
    Thread t = new Thread(new Runnable()
View Full Code Here

Examples of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter

  @Test
  public void testSimpleURI() throws Exception
  {
    final TransportClient transportClient = _clientFactory.getClient(new HashMap<String, String>());
    final Client client = new TransportClientAdapter(transportClient);

    // Note no trailing slash; the point of the test is to ensure this URI will
    // send a Request-URI of "/".
    URI uri = URI.create("http://localhost:" + _testServer.getPort());
    RestRequestBuilder rb = new RestRequestBuilder(uri);
    rb.setMethod("GET");
    RestRequest request = rb.build();
    Future<RestResponse> f = client.restRequest(request);

    // This will block
    RestResponse response = f.get();

    assertEquals(response.getStatus(), 200);

    String requestString = _testServer.getLastRequest();
    assertTrue(requestString.startsWith("GET / HTTP"), "Request '" + requestString +
            "' should have started with 'GET / HTTP'");

    final FutureCallback<None> callback = new FutureCallback<None>();
    client.shutdown(callback);
    callback.get();
  }
View Full Code Here

Examples of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter

  }

  @Test
  public void testNoProtocolVersionHeaderSuccess() throws InterruptedException, ExecutionException
  {
    final TransportClientAdapter client = new TransportClientAdapter(CLIENT_FACTORY.getClient(Collections.<String, String>emptyMap()));
    final RestRequestBuilder requestBuilder = new RestRequestBuilder(URI.create(URI_PREFIX + "greetings/1"));
    final RestRequest request = requestBuilder.build();
    Assert.assertTrue(request.getHeaders().isEmpty());

    final RestResponse response = client.restRequest(request).get();
    Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
    Assert.assertEquals(response.getHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION),
                        AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion().toString());
  }
View Full Code Here

Examples of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter

  }

  @Test
  public void testNoProtocolVersionHeaderFail() throws InterruptedException
  {
    final TransportClientAdapter client = new TransportClientAdapter(CLIENT_FACTORY.getClient(Collections.<String, String>emptyMap()));
    final RestRequestBuilder requestBuilder = new RestRequestBuilder(URI.create(URI_PREFIX));
    final RestRequest request = requestBuilder.build();
    Assert.assertTrue(request.getHeaders().isEmpty());

    try
    {
      client.restRequest(request).get();
    }
    catch (ExecutionException e)
    {
      final RestException exception = (RestException) e.getCause();
      final RestResponse response = exception.getResponse();
View Full Code Here

Examples of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter

      __metadata = new HashMap<String, Object>();
      if (restliProtocolVersion != null)
      {
        __metadata.put(RestConstants.RESTLI_PROTOCOL_VERSION_PROPERTY, restliProtocolVersion);
      }
      __client = new TransportClientAdapter(CLIENT_FACTORY.getClient(Collections.<String, String>emptyMap()));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.