use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.
the class TestResponseCompression method testAcceptEncodingConfiguration.
// Often fails in CI without a retry
@Test(dataProvider = "encodingsData", retryAnalyzer = SingleRetry.class)
public void testAcceptEncodingConfiguration(String responseContentEncodings, String expectedAcceptEncoding, String expectedContentEncoding) throws RemoteInvocationException {
Map<String, Object> properties = new HashMap<>();
properties.put(HttpClientFactory.HTTP_RESPONSE_CONTENT_ENCODINGS, responseContentEncodings);
properties.put(HttpClientFactory.HTTP_USE_RESPONSE_COMPRESSION, "true");
Client client = newTransportClient(properties);
Long[] ids = new Long[100];
for (int i = 0; i < ids.length; i++) {
ids[i] = (long) i;
}
Request<BatchResponse<Greeting>> request = new GreetingsBuilders().batchGet().ids(Arrays.asList(ids)).setHeader(EXPECTED_ACCEPT_ENCODING, expectedAcceptEncoding).build();
RestClient restClient = new RestClient(client, FILTERS_URI_PREFIX);
Response<BatchResponse<Greeting>> response = restClient.sendRequest(request).getResponse();
Assert.assertEquals(response.getHeader(TestCompressionServer.CONTENT_ENCODING_SAVED), expectedContentEncoding);
}
use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.
the class TestStreamingGreetings method testUpdateReturnAttachments.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testUpdateReturnAttachments(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
try {
// This will be echoed back in the form of an attachment.
final String headerAndAttachment = "someValue";
final Request<EmptyRecord> updateRequest = builders.update().id(1l).input(new Greeting()).setHeader("getHeader", headerAndAttachment).build();
sendNonTypicalRequestAndVerifyAttachments(updateRequest, headerAndAttachment);
} catch (Exception exception) {
Assert.fail();
}
}
use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.
the class TestMockHttpServerFactory method testCreateUsingPackageNames.
@Test
public void testCreateUsingPackageNames() throws IOException, RemoteInvocationException {
Map<String, Object> beans = getBeans();
boolean[] enableAsyncOptions = { true, false };
for (boolean enableAsync : enableAsyncOptions) {
HttpServer server = MockHttpServerFactory.create(PORT, new String[] { "com.linkedin.restli.example.impl" }, beans, enableAsync);
runTest(server);
}
}
use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.
the class RestClientTest method testRestLiResponseFuture.
@SuppressWarnings("deprecation")
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "sendRequestAndGetResponseOptions")
public void testRestLiResponseFuture(SendRequestOption sendRequestOption, GetResponseOption getResponseOption, TimeoutOption timeoutOption, ProtocolVersionOption versionOption, ProtocolVersion protocolVersion, String errorResponseHeaderName, ContentType contentType) throws ExecutionException, RemoteInvocationException, TimeoutException, InterruptedException, IOException {
final String ERR_KEY = "someErr";
final String ERR_VALUE = "WHOOPS!";
final String ERR_MSG = "whoops2";
final int HTTP_CODE = 200;
final int APP_CODE = 666;
final String CODE = "INVALID_INPUT";
final String DOC_URL = "https://example.com/errors/invalid-input";
final String REQUEST_ID = "abc123";
RestClient client = mockClient(ERR_KEY, ERR_VALUE, ERR_MSG, HTTP_CODE, APP_CODE, CODE, DOC_URL, REQUEST_ID, protocolVersion, errorResponseHeaderName);
Request<ErrorResponse> request = mockRequest(ErrorResponse.class, versionOption, contentType);
RequestBuilder<Request<ErrorResponse>> requestBuilder = mockRequestBuilder(request);
ResponseFuture<ErrorResponse> future = sendRequest(sendRequestOption, determineErrorHandlingBehavior(getResponseOption), client, request, requestBuilder);
Response<ErrorResponse> response = getOkResponse(getResponseOption, future, timeoutOption);
ErrorResponse e = response.getEntity();
Assert.assertNull(response.getError());
Assert.assertFalse(response.hasError());
Assert.assertEquals(HTTP_CODE, response.getStatus());
Assert.assertEquals(ERR_VALUE, e.getErrorDetails().data().getString(ERR_KEY));
Assert.assertEquals(APP_CODE, e.getServiceErrorCode().intValue());
Assert.assertEquals(ERR_MSG, e.getMessage());
Assert.assertEquals(CODE, e.getCode());
Assert.assertEquals(DOC_URL, e.getDocUrl());
Assert.assertEquals(REQUEST_ID, e.getRequestId());
Assert.assertEquals(EmptyRecord.class.getCanonicalName(), e.getErrorDetailType());
}
use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.
the class RestClientTest method testRestLiRemoteInvocationException.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "sendRequestOptions")
public void testRestLiRemoteInvocationException(SendRequestOption option, TimeoutOption timeoutOption, ProtocolVersionOption versionOption, ProtocolVersion protocolVersion, String errorResponseHeaderName, ContentType contentType) throws ExecutionException, TimeoutException, InterruptedException, RestLiDecodingException {
final int HTTP_CODE = 404;
final String ERR_MSG = "WHOOPS!";
RestClient client = mockClient(HTTP_CODE, ERR_MSG, protocolVersion);
Request<EmptyRecord> request = mockRequest(EmptyRecord.class, versionOption, contentType);
RequestBuilder<Request<EmptyRecord>> requestBuilder = mockRequestBuilder(request);
FutureCallback<Response<EmptyRecord>> callback = new FutureCallback<>();
try {
sendRequest(option, client, request, requestBuilder, callback);
Long l = timeoutOption._l;
TimeUnit timeUnit = timeoutOption._timeUnit;
Response<EmptyRecord> response = l == null ? callback.get() : callback.get(l, timeUnit);
Assert.fail("Should have thrown");
} catch (ExecutionException e) {
Throwable cause = e.getCause();
Assert.assertTrue(cause instanceof RemoteInvocationException, "Expected RemoteInvocationException not " + cause.getClass().getName());
RemoteInvocationException rlre = (RemoteInvocationException) cause;
Assert.assertTrue(rlre.getMessage().startsWith("Received error " + HTTP_CODE + " from server"));
Throwable rlCause = rlre.getCause();
Assert.assertTrue(rlCause instanceof RestException, "Expected RestException not " + rlCause.getClass().getName());
RestException rle = (RestException) rlCause;
Assert.assertEquals(ERR_MSG, rle.getResponse().getEntity().asString("UTF-8"));
Assert.assertEquals(HTTP_CODE, rle.getResponse().getStatus());
}
}
Aggregations