Search in sources :

Example 1 with RestEchoClient

use of com.linkedin.r2.sample.echo.rest.RestEchoClient in project rest.li by linkedin.

the class TestHttpsEcho method testHttpEcho.

/**
   * Test that https-enabled server and client can speak plain HTTP as well.
   */
@Test
public void testHttpEcho() throws Exception {
    final EchoService client = new RestEchoClient(Bootstrap.createHttpURI(Bootstrap.getEchoURI()), _client);
    final String msg = "This is a simple http echo message";
    final FutureCallback<String> callback = new FutureCallback<String>();
    client.echo(msg, callback);
    Assert.assertEquals(callback.get(), msg);
}
Also used : EchoService(com.linkedin.r2.sample.echo.EchoService) RestEchoClient(com.linkedin.r2.sample.echo.rest.RestEchoClient) FutureCallback(com.linkedin.common.callback.FutureCallback) Test(org.testng.annotations.Test)

Example 2 with RestEchoClient

use of com.linkedin.r2.sample.echo.rest.RestEchoClient in project rest.li by linkedin.

the class AbstractEchoServiceTest method testBadRestURI.

@Test
public void testBadRestURI() {
    final EchoService client = getEchoClient(_client, URI.create("/unknown-service"));
    if (!(client instanceof RestEchoClient)) {
        return;
    }
    final String msg = "This is a simple echo message";
    final FutureCallback<String> callback = new FutureCallback<String>();
    client.echo(msg, callback);
    try {
        callback.get();
        Assert.fail("Should have thrown an exception");
    } catch (Exception e) {
        Assert.assertTrue(e instanceof ExecutionException);
        Assert.assertTrue(e.getCause() instanceof RestException);
        RestException re = (RestException) e.getCause();
        Assert.assertEquals(re.getResponse().getStatus(), RestStatus.NOT_FOUND);
    }
}
Also used : EchoService(com.linkedin.r2.sample.echo.EchoService) RestEchoClient(com.linkedin.r2.sample.echo.rest.RestEchoClient) RestException(com.linkedin.r2.message.rest.RestException) ExecutionException(java.util.concurrent.ExecutionException) FutureCallback(com.linkedin.common.callback.FutureCallback) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) ExecutionException(java.util.concurrent.ExecutionException) RestException(com.linkedin.r2.message.rest.RestException) Test(org.testng.annotations.Test)

Example 3 with RestEchoClient

use of com.linkedin.r2.sample.echo.rest.RestEchoClient in project rest.li by linkedin.

the class TestGeneralEchoServiceTest method testBadRestURI.

@Test(enabled = false)
public void testBadRestURI() {
    final EchoService client = getEchoClient(_client, URI.create("/unknown-service"));
    if (!(client instanceof RestEchoClient)) {
        return;
    }
    final String msg = "This is a simple echo message";
    final FutureCallback<String> callback = new FutureCallback<>();
    client.echo(msg, callback);
    try {
        callback.get();
        Assert.fail("Should have thrown an exception");
    } catch (Exception e) {
        Assert.assertTrue(e instanceof ExecutionException);
        Assert.assertTrue(e.getCause() instanceof RestException);
        RestException re = (RestException) e.getCause();
        Assert.assertEquals(re.getResponse().getStatus(), RestStatus.NOT_FOUND);
    }
}
Also used : EchoService(com.linkedin.r2.sample.echo.EchoService) RestEchoClient(com.linkedin.r2.sample.echo.rest.RestEchoClient) RestException(com.linkedin.r2.message.rest.RestException) ExecutionException(java.util.concurrent.ExecutionException) FutureCallback(com.linkedin.common.callback.FutureCallback) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) ExecutionException(java.util.concurrent.ExecutionException) RestException(com.linkedin.r2.message.rest.RestException) AbstractEchoServiceTest(test.r2.integ.clientserver.providers.AbstractEchoServiceTest) Test(org.testng.annotations.Test)

Example 4 with RestEchoClient

use of com.linkedin.r2.sample.echo.rest.RestEchoClient in project rest.li by linkedin.

the class TestSslTimingKey method testSslTimingKey.

@Test
public void testSslTimingKey() throws Exception {
    if (isHttp2StreamBasedChannel())
        return;
    final EchoService client = new RestEchoClient(Bootstrap.createURI(_port, Bootstrap.getEchoURI(), true), createClient());
    final String msg = "This is a simple http echo message";
    final FutureCallback<String> callback = new FutureCallback<>();
    client.echo(msg, callback);
    Assert.assertEquals(callback.get(), msg);
    RequestContext context = _clientCaptureFilter.getRequestContext();
    @SuppressWarnings("unchecked") Map<TimingKey, TimingContext> map = (Map<TimingKey, TimingContext>) context.getLocalAttr("timings");
    Assert.assertNotNull(map);
    Assert.assertTrue(map.containsKey(SslHandshakeTimingHandler.TIMING_KEY));
    TimingContext timingContext = map.get(SslHandshakeTimingHandler.TIMING_KEY);
    Assert.assertNotNull(timingContext);
}
Also used : TimingKey(com.linkedin.r2.message.timing.TimingKey) EchoService(com.linkedin.r2.sample.echo.EchoService) RestEchoClient(com.linkedin.r2.sample.echo.rest.RestEchoClient) RequestContext(com.linkedin.r2.message.RequestContext) Map(java.util.Map) FutureCallback(com.linkedin.common.callback.FutureCallback) TimingContext(com.linkedin.r2.message.timing.TimingContextUtil.TimingContext) AbstractEchoServiceTest(test.r2.integ.clientserver.providers.AbstractEchoServiceTest) Test(org.testng.annotations.Test)

Example 5 with RestEchoClient

use of com.linkedin.r2.sample.echo.rest.RestEchoClient in project rest.li by linkedin.

the class TestAlpnUpgradePromise method testClearTestUpgradeFailure.

private void testClearTestUpgradeFailure() {
    final EchoService client = new RestEchoClient(Bootstrap.createURI(_port, Bootstrap.getEchoURI(), _serverProvider.isSsl()), _client);
    final String msg = "This is a simple http echo message";
    final FutureCallback<String> callback = new FutureCallback<>();
    try {
        client.echo(msg, callback);
        Assert.assertEquals(callback.get(), msg);
        Assert.fail("Should not have reached here !");
    } catch (Exception ex) {
        Throwable throwable = ExceptionUtils.getRootCause(ex);
        Assert.assertTrue(throwable instanceof IllegalStateException);
        Assert.assertEquals(throwable.getMessage(), "HTTP/2 clear text upgrade failed");
    }
}
Also used : EchoService(com.linkedin.r2.sample.echo.EchoService) RestEchoClient(com.linkedin.r2.sample.echo.rest.RestEchoClient) FutureCallback(com.linkedin.common.callback.FutureCallback)

Aggregations

FutureCallback (com.linkedin.common.callback.FutureCallback)9 RestEchoClient (com.linkedin.r2.sample.echo.rest.RestEchoClient)9 EchoService (com.linkedin.r2.sample.echo.EchoService)8 Test (org.testng.annotations.Test)5 AbstractEchoServiceTest (test.r2.integ.clientserver.providers.AbstractEchoServiceTest)3 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)2 RequestContext (com.linkedin.r2.message.RequestContext)2 RestException (com.linkedin.r2.message.rest.RestException)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimingContext (com.linkedin.r2.message.timing.TimingContextUtil.TimingContext)1 TimingKey (com.linkedin.r2.message.timing.TimingKey)1 Map (java.util.Map)1