use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.
the class TestDebugRequestHandlers method testParseqTraceDebugPutRequestHandlerRaw.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testParseqTraceDebugPutRequestHandlerRaw(RootBuilderWrapper<Long, Greeting> builders) throws URISyntaxException, ExecutionException, InterruptedException, RemoteInvocationException {
Long newId = createNewGreetingOnTheServer(builders);
RestRequest request = new RestRequestBuilder(new URI(URI_PREFIX + "greetingsPromise/" + newId + "/__debug/parseqtrace/raw")).setMethod("PUT").setEntity(createNewGreetingBytes(newId)).build();
sendRequestAndVerifyParseqTraceRaw(request);
}
use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.
the class TestRequestCompression method testUpdate.
@Test(dataProvider = "requestData", retryAnalyzer = ThreeRetries.class)
public void testUpdate(CompressionConfig requestCompressionConfig, String supportedEncodings, RestliRequestOptions restliRequestOptions, int messageLength, String testHelpHeader) throws RemoteInvocationException, CloneNotSupportedException, InterruptedException, ExecutionException, TimeoutException {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("R2 Netty Scheduler"));
Map<String, CompressionConfig> requestCompressionConfigs = new HashMap<>();
if (requestCompressionConfig != null) {
requestCompressionConfigs.put(SERVICE_NAME, requestCompressionConfig);
}
HttpClientFactory httpClientFactory = new HttpClientFactory.Builder().setFilterChain(FilterChains.empty()).setEventLoopGroup(new NioEventLoopGroup()).setShutDownFactory(true).setScheduleExecutorService(executor).setShutdownScheduledExecutorService(true).setCallbackExecutor(null).setShutdownCallbackExecutor(false).setJmxManager(AbstractJmxManager.NULL_JMX_MANAGER).setRequestCompressionThresholdDefault(500).setRequestCompressionConfigs(requestCompressionConfigs).build();
Map<String, String> properties = new HashMap<>();
properties.put(HttpClientFactory.HTTP_REQUEST_CONTENT_ENCODINGS, supportedEncodings);
properties.put(HttpClientFactory.HTTP_SERVICE_NAME, SERVICE_NAME);
TransportClientAdapter clientAdapter1 = new TransportClientAdapter(httpClientFactory.getClient(properties));
RestClient client = new RestClient(clientAdapter1, FILTERS_URI_PREFIX);
RootBuilderWrapper<Long, Greeting> builders = new RootBuilderWrapper<>(new GreetingsRequestBuilders(restliRequestOptions));
// GET
Request<Greeting> request = builders.get().id(1L).build();
ResponseFuture<Greeting> future = client.sendRequest(request);
Response<Greeting> greetingResponse = future.getResponse();
String response1 = greetingResponse.getEntity().getMessage();
Assert.assertNotNull(response1);
// POST
Greeting greeting = new Greeting(greetingResponse.getEntity().data().copy());
char[] As = new char[messageLength];
Arrays.fill(As, 'A');
String message = new String(As);
greeting.setMessage(message);
Request<EmptyRecord> writeRequest = builders.update().id(1L).input(greeting).setHeader(TEST_HELP_HEADER, testHelpHeader).build();
client.sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
Request<Greeting> request2 = builders.get().id(1L).build();
ResponseFuture<Greeting> future2 = client.sendRequest(request2);
String response2 = future2.getResponse().getEntity().getMessage();
Assert.assertEquals(response2, message);
FutureCallback<None> callback1 = new FutureCallback<>();
client.shutdown(callback1);
callback1.get(30, TimeUnit.SECONDS);
FutureCallback<None> callback2 = new FutureCallback<>();
httpClientFactory.shutdown(callback2);
callback2.get(30, TimeUnit.SECONDS);
}
use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.
the class TestCustomDocumentationHandler method testOptionsJson.
@Test
public void testOptionsJson() throws RemoteInvocationException {
Request<OptionsResponse> optionsRequest = new GreetingsRequestBuilders().options().addParam("format", RestLiDocumentationRenderer.DocumentationFormat.JSON.toString().toLowerCase()).build();
OptionsResponse optionsResponse = getClient().sendRequest(optionsRequest).getResponse().getEntity();
Assert.assertEquals(1, optionsResponse.getResourceSchemas().size());
Assert.assertNotNull(optionsResponse.getResourceSchemas().get("com.linkedin.restli.examples.greetings.client.greetings"));
Assert.assertEquals(optionsResponse.getDataSchemas().size(), 10);
List<String> expectedModels = new ArrayList<>(Arrays.asList("com.linkedin.restli.examples.greetings.api.Greeting", "com.linkedin.restli.examples.greetings.api.SearchMetadata", "com.linkedin.restli.examples.groups.api.TransferOwnershipRequest", "com.linkedin.restli.examples.greetings.api.Empty", "com.linkedin.restli.examples.greetings.api.Tone"));
List<String> expectedCustomModels = expectedModels.stream().map(name -> name + CUSTOM_SUFFIX).collect(Collectors.toList());
expectedModels.addAll(expectedCustomModels);
Assert.assertTrue(optionsResponse.getDataSchemas().keySet().containsAll(expectedModels));
for (String schema : expectedModels) {
NamedDataSchema dataSchema = (NamedDataSchema) optionsResponse.getDataSchemas().get(schema);
Assert.assertEquals(dataSchema.getFullName(), schema);
}
}
use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.
the class TestStreamingGreetings method fullStreamTest.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void fullStreamTest(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
// Perform a create to the server to store some bytes via an attachment.
final byte[] clientSuppliedBytes = "ClientSupplied".getBytes();
final RestLiTestAttachmentDataSource greetingAttachment = new RestLiTestAttachmentDataSource("1", ByteString.copy(clientSuppliedBytes));
final RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> methodBuilderWrapper = builders.create();
methodBuilderWrapper.appendSingleAttachment(greetingAttachment);
// Provide a header to verify the server's ability to transform the first part into the RestRequest.
methodBuilderWrapper.setHeader("createHeader", "createHeaderValue");
final Greeting greeting = new Greeting().setMessage("A greeting with an attachment");
final Request<EmptyRecord> createRequest = methodBuilderWrapper.input(greeting).build();
try {
final Response<EmptyRecord> createResponse = getClient().sendRequest(createRequest).getResponse();
Assert.assertEquals(createResponse.getStatus(), 201);
// Verify that headers propagate properly.
Assert.assertEquals(createResponse.getHeader("createHeader"), "createHeaderValue");
} catch (final RestLiResponseException responseException) {
Assert.fail("We should not reach here!", responseException);
}
// Then perform a GET and verify the bytes are present
try {
final Request<Greeting> getRequest = builders.get().id(1l).setHeader("getHeader", "getHeaderValue").build();
final Response<Greeting> getResponse = getClient().sendRequest(getRequest).getResponse();
Assert.assertEquals(getResponse.getStatus(), 200);
// Verify that headers propagate properly.
Assert.assertEquals(getResponse.getHeader("getHeader"), "getHeaderValue");
Assert.assertEquals(getResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE), RestConstants.HEADER_VALUE_APPLICATION_JSON);
Assert.assertEquals(getResponse.getEntity().getMessage(), "Your greeting has an attachment since you were kind and decided you wanted to read it!");
Assert.assertTrue(getResponse.hasAttachments(), "We must have some response attachments");
RestLiAttachmentReader attachmentReader = getResponse.getAttachmentReader();
final CountDownLatch latch = new CountDownLatch(1);
final GreetingBlobReaderCallback greetingBlobReaderCallback = new GreetingBlobReaderCallback(latch);
attachmentReader.registerAttachmentReaderCallback(greetingBlobReaderCallback);
try {
latch.await(3000, TimeUnit.SECONDS);
Assert.assertEquals(greetingBlobReaderCallback.getAttachmentList().size(), 1);
Assert.assertEquals(greetingBlobReaderCallback.getAttachmentList().get(0), ByteString.copy(clientSuppliedBytes));
} catch (Exception exception) {
Assert.fail();
}
} catch (final RestLiResponseException responseException) {
Assert.fail("We should not reach here!", responseException);
}
}
use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.
the class TestStreamingGreetings method testDeleteReturnAttachments.
// The delete and update tests here are simply to show that although not typical, it is possible to return
// attachments from DELETE, UPDATE, PARTIAL_UPDATE, BATCH_DELETE, BATCH_UPDATE, and BATCH_PARTIAL_UPDATE. For the sake of
// brevity DELETE and UPDATE are used as examples.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testDeleteReturnAttachments(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> deleteRequest = builders.delete().id(1l).setHeader("getHeader", headerAndAttachment).build();
sendNonTypicalRequestAndVerifyAttachments(deleteRequest, headerAndAttachment);
} catch (Exception exception) {
Assert.fail();
}
}
Aggregations