Search in sources :

Example 16 with BatchResponse

use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.

the class TestCompressionServer method getOldCookbookBatchGetResult.

private Greeting getOldCookbookBatchGetResult(RestClient client, RestliRequestOptions requestOptions) throws RemoteInvocationException {
    Request<BatchResponse<Greeting>> request = new GreetingsBuilders(requestOptions).batchGet().ids(1L).build();
    ResponseFuture<BatchResponse<Greeting>> future = client.sendRequest(request);
    Response<BatchResponse<Greeting>> greetingResponse = future.getResponse();
    checkContentEncodingHeaderIsAbsent(greetingResponse);
    return greetingResponse.getEntity().getResults().get("1");
}
Also used : GreetingsBuilders(com.linkedin.restli.examples.greetings.client.GreetingsBuilders) BatchResponse(com.linkedin.restli.common.BatchResponse)

Example 17 with BatchResponse

use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.

the class TestScatterGather method testSendGetSGRequests.

private static void testSendGetSGRequests(ScatterGatherBuilder<Greeting> sg, Long[] requestIds) throws ServiceUnavailableException, InterruptedException {
    Collection<ScatterGatherBuilder.RequestInfo<Greeting>> scatterGatherRequests = buildScatterGatherGetRequests(sg, requestIds);
    final Map<String, Greeting> results = new ConcurrentHashMap<String, Greeting>();
    final CountDownLatch latch = new CountDownLatch(scatterGatherRequests.size());
    final List<Throwable> errors = new ArrayList<Throwable>();
    final List<BatchResponse<Greeting>> responses = new ArrayList<BatchResponse<Greeting>>();
    for (ScatterGatherBuilder.RequestInfo<Greeting> requestInfo : scatterGatherRequests) {
        Callback<Response<BatchResponse<Greeting>>> cb = new Callback<Response<BatchResponse<Greeting>>>() {

            @Override
            public void onSuccess(Response<BatchResponse<Greeting>> response) {
                results.putAll(response.getEntity().getResults());
                synchronized (responses) {
                    responses.add(response.getEntity());
                }
                latch.countDown();
            }

            @Override
            public void onError(Throwable e) {
                synchronized (errors) {
                    errors.add(e);
                }
                latch.countDown();
            }
        };
        REST_CLIENT.sendRequest(requestInfo.getRequest(), requestInfo.getRequestContext(), cb);
    }
    latch.await();
    if (!errors.isEmpty()) {
        Assert.fail("Errors in scatter/gather: " + errors.toString());
    }
    Assert.assertEquals(results.values().size(), requestIds.length);
    Set<Set<String>> responseIdSets = new HashSet<Set<String>>();
    Set<Long> responseIds = new HashSet<Long>();
    for (BatchResponse<Greeting> response : responses) {
        Set<String> theseIds = response.getResults().keySet();
        //no duplicate requests
        Assert.assertFalse(responseIdSets.contains(theseIds));
        for (String id : theseIds) {
            //no duplicate ids
            Assert.assertFalse(responseIds.contains(Long.parseLong(id)));
            responseIds.add(Long.parseLong(id));
        }
        responseIdSets.add(theseIds);
    }
    Assert.assertTrue(responseIds.containsAll(Arrays.asList(requestIds)));
    Assert.assertEquals(responseIds.size(), requestIds.length);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) Set(java.util.Set) HashSet(java.util.HashSet) BatchResponse(com.linkedin.restli.common.BatchResponse) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) EntityResponse(com.linkedin.restli.common.EntityResponse) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) BatchResponse(com.linkedin.restli.common.BatchResponse) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Callback(com.linkedin.common.callback.Callback) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashSet(java.util.HashSet)

Example 18 with BatchResponse

use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.

the class TestScatterGather method testBuildSGGetRequests.

private static void testBuildSGGetRequests(int numEndpoints, ScatterGatherBuilder<Greeting> sg, Long[] ids) throws ServiceUnavailableException {
    Collection<ScatterGatherBuilder.RequestInfo<Greeting>> requests = buildScatterGatherGetRequests(sg, ids);
    Assert.assertEquals(requests.size(), numEndpoints);
    Set<Set<String>> requestIdSets = new HashSet<Set<String>>();
    Set<Long> requestIds = new HashSet<Long>();
    for (ScatterGatherBuilder.RequestInfo<Greeting> requestInfo : requests) {
        //URI will be something like "greetings/?ids=21&ids=4&ids=53&ids=60&ids=66&ids=88&ids=93&foo=bar"
        BatchRequest<BatchResponse<Greeting>> request = requestInfo.getBatchRequest();
        Set<String> expectedParams = new HashSet<String>();
        expectedParams.add(RestConstants.QUERY_BATCH_IDS_PARAM);
        expectedParams.add("foo");
        expectedParams.add(RestConstants.FIELDS_PARAM);
        Set<PathSpec> expectedFields = Collections.singleton(new PathSpec("message"));
        testRequest(request, expectedParams, expectedFields, null, requestIdSets, requestIds);
    }
    Assert.assertTrue(requestIds.containsAll(Arrays.asList(ids)));
    Assert.assertEquals(requestIds.size(), ids.length);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) Set(java.util.Set) HashSet(java.util.HashSet) BatchResponse(com.linkedin.restli.common.BatchResponse) PathSpec(com.linkedin.data.schema.PathSpec) HashSet(java.util.HashSet)

Example 19 with BatchResponse

use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.

the class TestCustomTypesRequestBuilders method testCollectionBatchGetKey.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "request2BatchDataProvider")
public void testCollectionBatchGetKey(ProtocolVersion version, String expectedUri) throws IOException, RestException {
    Request<BatchResponse<Greeting>> request = new CustomTypes2Builders().batchGet().ids(new CustomLong(1L), new CustomLong(2L), new CustomLong(3L)).build();
    checkRequestBuilder(request, ResourceMethod.BATCH_GET, BatchResponseDecoder.class, expectedUri, null, version);
}
Also used : BatchResponse(com.linkedin.restli.common.BatchResponse) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) CustomTypes2Builders(com.linkedin.restli.examples.greetings.client.CustomTypes2Builders) Test(org.testng.annotations.Test)

Example 20 with BatchResponse

use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.

the class TestCustomTypesClient method testCollectionBatchGet.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionBatchGet(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    Request<BatchResponse<Greeting>> request = new CustomTypes2Builders(requestOptions).batchGet().ids(new CustomLong(1L), new CustomLong(2L), new CustomLong(3L)).build();
    Map<String, Greeting> greetings = getClient().sendRequest(request).getResponse().getEntity().getResults();
    Assert.assertEquals(greetings.size(), 3);
    Assert.assertEquals(greetings.get("1").getId().longValue(), 1L);
    Assert.assertEquals(greetings.get("2").getId().longValue(), 2L);
    Assert.assertEquals(greetings.get("3").getId().longValue(), 3L);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchResponse(com.linkedin.restli.common.BatchResponse) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) ByteString(com.linkedin.data.ByteString) CustomTypes2Builders(com.linkedin.restli.examples.greetings.client.CustomTypes2Builders) Test(org.testng.annotations.Test)

Aggregations

BatchResponse (com.linkedin.restli.common.BatchResponse)25 Test (org.testng.annotations.Test)19 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)9 HashMap (java.util.HashMap)8 DataMap (com.linkedin.data.DataMap)6 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)6 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)6 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)6 ResourceContext (com.linkedin.restli.server.ResourceContext)6 GreetingsBuilders (com.linkedin.restli.examples.greetings.client.GreetingsBuilders)5 RestLiResponseData (com.linkedin.restli.server.RestLiResponseData)5 Map (java.util.Map)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)4 UpdateStatus (com.linkedin.restli.common.UpdateStatus)4 Foo (com.linkedin.pegasus.generator.examples.Foo)3 HashSet (java.util.HashSet)3 RestClient (com.linkedin.restli.client.RestClient)2 CreateStatus (com.linkedin.restli.common.CreateStatus)2 EntityResponse (com.linkedin.restli.common.EntityResponse)2