Search in sources :

Example 56 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestMaxBatchSize method testBatchGetWithMaxBatchSizeBeyondLimitation.

@Test
public void testBatchGetWithMaxBatchSizeBeyondLimitation() throws RemoteInvocationException {
    BatchGetEntityRequest<Long, Greeting> request = new BatchGreetingRequestBuilders().batchGet().ids(1l, 2l, 3l).build();
    try {
        getClient().sendRequest(request).getResponse();
        Assert.fail("The batch size is larger than the allowed max batch size should cause an exception.");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), HttpStatus.S_400_BAD_REQUEST.getCode());
        Assert.assertEquals(e.getServiceErrorMessage(), "The request batch size: " + "3 is larger than the allowed max batch size: 2 for method: batch_get");
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) BatchGreetingRequestBuilders(com.linkedin.restli.examples.greetings.client.BatchGreetingRequestBuilders) Test(org.testng.annotations.Test)

Example 57 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestCustomCrudParams method testCookbookCrudParams.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testCookbookCrudParams(RootBuilderWrapper<Long, Greeting> builders) throws Exception {
    try {
        Request<Greeting> request = builders.get().id(1L).build();
        ResponseFuture<Greeting> future = getClient().sendRequest(request);
        @SuppressWarnings("unused") Response<Greeting> greetingResponse = future.getResponse();
        Assert.fail("expected response exception");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getServiceErrorMessage(), "Invalid auth token");
    }
    // GET
    Request<Greeting> request = builders.get().id(1L).setQueryParam("auth", "PLEASE").build();
    ResponseFuture<Greeting> future = getClient().sendRequest(request);
    Response<Greeting> greetingResponse = future.getResponse();
    // POST
    Greeting greeting = new Greeting(greetingResponse.getEntity().data().copy());
    greeting.setMessage("This is a new message!");
    Request<EmptyRecord> writeRequest = builders.update().id(1L).input(greeting).setQueryParam("auth", "PLEASE").build();
    getClient().sendRequest(writeRequest).getResponse();
    // GET again, to verify that our POST worked.
    Request<Greeting> request2 = builders.get().id(1L).setQueryParam("auth", "PLEASE").build();
    ResponseFuture<Greeting> future2 = getClient().sendRequest(request2);
    greetingResponse = future2.get();
    Assert.assertEquals(greetingResponse.getEntity().getMessage(), "This is a new message!");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 58 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestExceptionsResource2 method testExceptionWithValue.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "exceptionHandlingModesDataProvider")
public void testExceptionWithValue(boolean explicit, ErrorHandlingBehavior errorHandlingBehavior, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Response<Integer> response = null;
    RestLiResponseException exception = null;
    final Request<Integer> req = builders.<Integer>action("ExceptionWithValue").build();
    try {
        ResponseFuture<Integer> future;
        if (explicit) {
            future = getClient().sendRequest(req, errorHandlingBehavior);
        } else {
            future = getClient().sendRequest(req);
        }
        response = future.getResponse();
        if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR) {
            Assert.fail("expected exception");
        }
    } catch (RestLiResponseException e) {
        if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR) {
            exception = e;
        } else {
            Assert.fail("not expected exception");
        }
    }
    if (explicit && errorHandlingBehavior == ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS) {
        Assert.assertNotNull(response);
        Assert.assertTrue(response.hasError());
        exception = response.getError();
        Assert.assertEquals(response.getStatus(), HttpStatus.S_500_INTERNAL_SERVER_ERROR.getCode());
        Assert.assertNotNull(response.getEntity());
        Assert.assertSame(response.getEntity(), 42);
    }
    Assert.assertNotNull(exception);
    Assert.assertTrue(exception.hasDecodedResponse());
    Assert.assertEquals(exception.getStatus(), HttpStatus.S_500_INTERNAL_SERVER_ERROR.getCode());
    final DataMap respEntityMap = DataMapUtils.readMap(exception.getResponse());
    Assert.assertSame(respEntityMap.getInteger("value"), 42);
}
Also used : RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 59 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestLatencyInstrumentation method makeUpstreamRequest.

/**
 * Make the "upstream" request (as opposed to the "downstream" request made from the resource method) using a set of
 * test parameters. Waits for the timing keys to be recorded by the {@link InstrumentationTrackingFilter} before
 * returning.
 * @param useStreaming parameter from the test method
 * @param forceException parameter from the test method
 */
private void makeUpstreamRequest(boolean useStreaming, boolean forceException, boolean useScatterGather) throws RemoteInvocationException, InterruptedException {
    InstrumentationControl instrumentationControl = new InstrumentationControl().setServiceUriPrefix(FILTERS_URI_PREFIX).setUseStreaming(useStreaming).setForceException(forceException).setUseScatterGather(useScatterGather);
    CreateIdEntityRequest<Long, InstrumentationControl> createRequest = new LatencyInstrumentationBuilders().createAndGet().input(instrumentationControl).build();
    ResponseFuture<IdEntityResponse<Long, InstrumentationControl>> response = getClient().sendRequest(createRequest);
    try {
        response.getResponseEntity();
        if (forceException) {
            Assert.fail("Forcing exception, should've failed.");
        }
    } catch (RestLiResponseException e) {
        if (e.getStatus() != 400) {
            Assert.fail("Server responded with a non-400 error: " + e.getServiceErrorStackTrace());
        }
        if (!forceException) {
            Assert.fail("Not forcing exception, didn't expect failure.");
        }
    }
    // Wait for the server to send the response and save the timings
    final boolean success = _countDownLatch.await(10, TimeUnit.SECONDS);
    if (!success) {
        Assert.fail("Request timed out!");
    }
}
Also used : IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) InstrumentationControl(com.linkedin.restli.examples.instrumentation.api.InstrumentationControl) LatencyInstrumentationBuilders(com.linkedin.restli.examples.instrumentation.client.LatencyInstrumentationBuilders)

Example 60 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestRestLiValidationWithProjection method testNoProjection.

@Test
public void testNoProjection() throws RemoteInvocationException {
    RootBuilderWrapper<Integer, ValidationDemo> wrapper = new RootBuilderWrapper<>(new AutoValidationWithProjectionBuilders());
    Request<CollectionResponse<ValidationDemo>> request = wrapper.findBy("searchWithProjection").build();
    try {
        _restClientAuto.sendRequest(request).getResponse();
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getServiceErrorMessage(), EXPECTED_VALIDATION_DEMO_FAILURE_MESSAGE);
    }
}
Also used : AutoValidationWithProjectionBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders) CollectionResponse(com.linkedin.restli.common.CollectionResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Aggregations

RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)85 Test (org.testng.annotations.Test)75 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)30 StringMap (com.linkedin.data.template.StringMap)15 FlowId (org.apache.gobblin.service.FlowId)11 EmptyRecord (com.linkedin.restli.common.EmptyRecord)10 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)10 ExecutionException (java.util.concurrent.ExecutionException)9 RestResponse (com.linkedin.r2.message.rest.RestResponse)7 FlowConfig (org.apache.gobblin.service.FlowConfig)7 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)6 ErrorResponse (com.linkedin.restli.common.ErrorResponse)5 HashMap (java.util.HashMap)5 Schedule (org.apache.gobblin.service.Schedule)5 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)4 MockRestliResponseExceptionBuilder (com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder)4 CollectionResponse (com.linkedin.restli.common.CollectionResponse)4 AutoValidationWithProjectionBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders)4 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)4 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)4