Search in sources :

Example 16 with RemoteInvocationException

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);
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 17 with RemoteInvocationException

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);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) HashMap(java.util.HashMap) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) FutureCallback(com.linkedin.common.callback.FutureCallback) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NamedThreadFactory(com.linkedin.r2.util.NamedThreadFactory) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) RestClient(com.linkedin.restli.client.RestClient) None(com.linkedin.common.util.None) CompressionConfig(com.linkedin.r2.filter.CompressionConfig) Test(org.testng.annotations.Test)

Example 18 with RemoteInvocationException

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);
    }
}
Also used : AfterClass(org.testng.annotations.AfterClass) Arrays(java.util.Arrays) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) BeforeClass(org.testng.annotations.BeforeClass) RestLiJSONDocumentationRenderer(com.linkedin.restli.docgen.RestLiJSONDocumentationRenderer) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) DefaultDocumentationRequestHandler(com.linkedin.restli.docgen.DefaultDocumentationRequestHandler) RestLiConfig(com.linkedin.restli.server.RestLiConfig) IOException(java.io.IOException) Test(org.testng.annotations.Test) DataSchemaResolver(com.linkedin.data.schema.DataSchemaResolver) RestLiResourceRelationship(com.linkedin.restli.docgen.RestLiResourceRelationship) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) DataMap(com.linkedin.data.DataMap) RestLiDocumentationRenderer(com.linkedin.restli.docgen.RestLiDocumentationRenderer) List(java.util.List) Assert(org.testng.Assert) Request(com.linkedin.restli.client.Request) Map(java.util.Map) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) OptionsResponse(com.linkedin.restli.common.OptionsResponse) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) ArrayList(java.util.ArrayList) OptionsResponse(com.linkedin.restli.common.OptionsResponse) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) Test(org.testng.annotations.Test)

Example 19 with RemoteInvocationException

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);
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) CountDownLatch(java.util.concurrent.CountDownLatch) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) RestLiTestAttachmentDataSource(com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource) RestLiAttachmentReader(com.linkedin.restli.common.attachments.RestLiAttachmentReader) Test(org.testng.annotations.Test)

Example 20 with RemoteInvocationException

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();
    }
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) ByteString(com.linkedin.data.ByteString) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)32 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)29 RestRequest (com.linkedin.r2.message.rest.RestRequest)13 RequestContext (com.linkedin.r2.message.RequestContext)10 HashMap (java.util.HashMap)10 ErrorResponse (com.linkedin.restli.common.ErrorResponse)8 URI (java.net.URI)8 FutureCallback (com.linkedin.common.callback.FutureCallback)7 EmptyRecord (com.linkedin.restli.common.EmptyRecord)7 Map (java.util.Map)7 ExecutionException (java.util.concurrent.ExecutionException)7 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)6 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)6 Callback (com.linkedin.common.callback.Callback)5 ByteString (com.linkedin.data.ByteString)5 RestException (com.linkedin.r2.message.rest.RestException)5 TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)5 TimeoutException (java.util.concurrent.TimeoutException)5 RestResponse (com.linkedin.r2.message.rest.RestResponse)4 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)4