Search in sources :

Example 41 with UpdateStatus

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

the class TestRestLiScatterGather method testSendSGPartialUpdateRequests.

// BatchPartialUpdateRequest
private static void testSendSGPartialUpdateRequests(RestClient restClient, Map<Long, PatchRequest<Greeting>> inputs, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    @SuppressWarnings("unchecked") BatchPartialUpdateRequest<Long, Greeting> request = (BatchPartialUpdateRequest<Long, Greeting>) builders.batchPartialUpdate().patchInputs(inputs).setParam("foo", "bar").build();
    BatchKVResponse<Long, UpdateStatus> result = restClient.sendRequest(request).getResponse().getEntity();
    Assert.assertEquals(result.getResults().size(), inputs.size());
    UpdateStatus item = result.getResults().values().iterator().next();
    Assert.assertFalse(item.hasError());
    Assert.assertEquals(result.getErrors().size(), 0);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) UpdateStatus(com.linkedin.restli.common.UpdateStatus)

Example 42 with UpdateStatus

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

the class TestScatterGather method testSendSGKVRequests.

private static void testSendSGKVRequests(Collection<ScatterGatherBuilder.KVRequestInfo<Long, UpdateStatus>> scatterGatherRequests, Long[] requestIds) throws InterruptedException {
    final Map<Long, UpdateStatus> results = new ConcurrentHashMap<>();
    final CountDownLatch latch = new CountDownLatch(scatterGatherRequests.size());
    final List<Throwable> errors = new ArrayList<>();
    final List<BatchKVResponse<Long, UpdateStatus>> responses = new ArrayList<>();
    for (ScatterGatherBuilder.KVRequestInfo<Long, UpdateStatus> requestInfo : scatterGatherRequests) {
        Callback<Response<BatchKVResponse<Long, UpdateStatus>>> cb = new Callback<Response<BatchKVResponse<Long, UpdateStatus>>>() {

            @Override
            public void onSuccess(Response<BatchKVResponse<Long, UpdateStatus>> 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();
            }
        };
        BatchRequest<BatchKVResponse<Long, UpdateStatus>> request = requestInfo.getRequest();
        RequestContext requestContext = requestInfo.getRequestContext();
        REST_CLIENT.sendRequest(request, requestContext, cb);
    }
    latch.await();
    if (!errors.isEmpty()) {
        Assert.fail("Errors in scatter/gather: " + errors.toString());
    }
    Assert.assertEquals(results.values().size(), requestIds.length);
    Set<Set<Long>> responseIdSets = new HashSet<>();
    Set<Long> responseIds = new HashSet<>();
    for (BatchKVResponse<Long, UpdateStatus> response : responses) {
        Set<Long> theseIds = response.getResults().keySet();
        // no duplicate requests
        Assert.assertFalse(responseIdSets.contains(theseIds));
        for (Long id : theseIds) {
            // no duplicate ids
            Assert.assertFalse(responseIds.contains(id));
            responseIds.add(id);
        }
        responseIdSets.add(theseIds);
    }
    Assert.assertTrue(responseIds.containsAll(Arrays.asList(requestIds)));
    Assert.assertEquals(responseIds.size(), requestIds.length);
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) 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) RequestContext(com.linkedin.r2.message.RequestContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashSet(java.util.HashSet)

Aggregations

UpdateStatus (com.linkedin.restli.common.UpdateStatus)42 HashMap (java.util.HashMap)27 Test (org.testng.annotations.Test)22 Map (java.util.Map)18 DataMap (com.linkedin.data.DataMap)16 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)15 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)12 ArrayList (java.util.ArrayList)11 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)8 BatchResponse (com.linkedin.restli.common.BatchResponse)7 CompoundKey (com.linkedin.restli.common.CompoundKey)7 EntityResponse (com.linkedin.restli.common.EntityResponse)7 PatchRequest (com.linkedin.restli.common.PatchRequest)6 BatchResponseEntry (com.linkedin.restli.internal.server.response.BatchResponseEnvelope.BatchResponseEntry)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)5 ErrorResponse (com.linkedin.restli.common.ErrorResponse)5 Message (com.linkedin.restli.examples.greetings.api.Message)5 TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)5 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)5