Search in sources :

Example 16 with EchoService

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

the class TestAlpnUpgradePromise method testAlpnFailure.

public void testAlpnFailure() throws Exception {
    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(), "Unsupported protocol 'http/1.1' is negotiated.");
    }
}
Also used : EchoService(com.linkedin.r2.sample.echo.EchoService) RestEchoClient(com.linkedin.r2.sample.echo.rest.RestEchoClient) FutureCallback(com.linkedin.common.callback.FutureCallback)

Example 17 with EchoService

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

the class TestAlpnUpgradePromise method testClientMessageEcho.

public void testClientMessageEcho() throws Exception {
    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<>();
    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)

Example 18 with EchoService

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

the class TestGeneralEchoServiceTest method testFilterChainOnException.

@Test
public void testFilterChainOnException() throws Exception {
    final EchoService client = getEchoClient(_client, URI.create("/unknown-service"));
    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) {
    // expected
    }
    // Make sure the server got its wire attribute
    Assert.assertEquals(_serverCaptureFilter.getRequest().get(_toServerKey), _toServerValue);
    // Make sure the client got its wire attribute, but not the server's wire attribute
    Assert.assertEquals(_clientCaptureFilter.getResponse().get(_toClientKey), _toClientValue);
    Assert.assertNull(_clientCaptureFilter.getResponse().get(_toServerKey));
}
Also used : EchoService(com.linkedin.r2.sample.echo.EchoService) 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 19 with EchoService

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

the class TestGeneralEchoServiceTest method testEcho.

@Test
public void testEcho() throws Exception {
    final EchoService client = getEchoClient(_client, Bootstrap.getEchoURI());
    final String msg = "This is a simple echo message";
    final FutureCallback<String> callback = new FutureCallback<>();
    client.echo(msg, callback);
    String actual = callback.get();
    Assert.assertEquals(actual, msg);
    Assert.assertEquals(_clientLengthFilter.getRequestEntityLength(), msg.length());
    Assert.assertEquals(_clientLengthFilter.getResponseEntityLength(), msg.length());
    Assert.assertEquals(_serverLengthFilter.getRequestEntityLength(), msg.length());
    Assert.assertEquals(_serverLengthFilter.getResponseEntityLength(), msg.length());
}
Also used : EchoService(com.linkedin.r2.sample.echo.EchoService) FutureCallback(com.linkedin.common.callback.FutureCallback) AbstractEchoServiceTest(test.r2.integ.clientserver.providers.AbstractEchoServiceTest) Test(org.testng.annotations.Test)

Example 20 with EchoService

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

the class TestGeneralEchoServiceTest method testUnknownServiceUri.

@Test
public void testUnknownServiceUri() {
    final EchoService client = getEchoClient(_client, URI.create("/unknown-service"));
    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) {
    // expected
    }
}
Also used : EchoService(com.linkedin.r2.sample.echo.EchoService) 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)

Aggregations

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