Search in sources :

Example 1 with StringKeysRequestBuilders

use of com.linkedin.restli.examples.greetings.client.StringKeysRequestBuilders in project rest.li by linkedin.

the class TestResponseDecoder method testNonRestliServerErrorHandling.

/**
 * This test tests 2 things in combo here:
 * 1) BatchEntityResponseDecoder could be invoked in some cases to try to decode a empty response dataMap when
 * non-rest.li server error returns, in this test, we simulate that by passing a over-size URL param
 * {@link com.linkedin.restli.internal.client.ExceptionUtil#exceptionForThrowable(java.lang.Throwable, com.linkedin.restli.internal.client.RestResponseDecoder)}
 *
 * 2) CallbackAdapter and its subclasses could have error while its dealing with error itself, this test make sure it
 * pass the 'new' error to its inner callback's onError method.
 * {@link CallbackAdapter#onError(java.lang.Throwable)}
 */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "dataProvider", retryAnalyzer = ThreeRetries.class)
public void testNonRestliServerErrorHandling(RestliRequestOptions requestOptions) throws Exception {
    Set<String> keys = new HashSet<>();
    keys.add(createDataSize(SERVER_HEADER_OVERLOAD_SIZE));
    BatchGetEntityRequest<String, Message> req = new StringKeysRequestBuilders(requestOptions).batchGet().ids(keys).build();
    ResponseFuture<BatchKVResponse<String, EntityResponse<Message>>> batchKVResponseResponseFuture = getClient().sendRequest(req);
    try {
        batchKVResponseResponseFuture.getResponse();
        Assert.fail("Exception should have thrown before this point!");
    } catch (Throwable e) {
        Assert.assertTrue(e instanceof RestLiResponseException);
        Assert.assertEquals(((RestLiResponseException) e).getStatus(), 414);
    }
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) StringKeysRequestBuilders(com.linkedin.restli.examples.greetings.client.StringKeysRequestBuilders) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) HashSet(java.util.HashSet) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) Test(org.testng.annotations.Test)

Example 2 with StringKeysRequestBuilders

use of com.linkedin.restli.examples.greetings.client.StringKeysRequestBuilders in project rest.li by linkedin.

the class TestEscapeCharsInStringKeys method testBatchGetEntityWithSimpleKey.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestStringKeysOptionsDataProvider")
public void testBatchGetEntityWithSimpleKey(RestliRequestOptions requestOptions) throws Exception {
    Set<String> keys = new HashSet<>();
    keys.add(key1());
    keys.add(key2());
    Request<BatchKVResponse<String, EntityResponse<Message>>> req = new StringKeysRequestBuilders(requestOptions).batchGet().ids(keys).build();
    BatchKVResponse<String, EntityResponse<Message>> response = getClient().sendRequest(req).get().getEntity();
    Map<String, EntityResponse<Message>> results = response.getResults();
    Assert.assertEquals(results.get(key1()).getEntity().getMessage(), key1(), "Message should match key for key1");
    Assert.assertEquals(results.get(key2()).getEntity().getMessage(), key2(), "Message should match key for key2");
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) EntityResponse(com.linkedin.restli.common.EntityResponse) StringKeysRequestBuilders(com.linkedin.restli.examples.greetings.client.StringKeysRequestBuilders) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)2 Message (com.linkedin.restli.examples.greetings.api.Message)2 StringKeysRequestBuilders (com.linkedin.restli.examples.greetings.client.StringKeysRequestBuilders)2 HashSet (java.util.HashSet)2 Test (org.testng.annotations.Test)2 EntityResponse (com.linkedin.restli.common.EntityResponse)1 RestLiIntegrationTest (com.linkedin.restli.examples.RestLiIntegrationTest)1