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");
}
}
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!");
}
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);
}
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!");
}
}
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);
}
}
Aggregations