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