use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestCompressionServer method getNewCookbookBatchGetResult.
private Greeting getNewCookbookBatchGetResult(RestClient client, RestliRequestOptions requestOptions) throws RemoteInvocationException {
Request<BatchKVResponse<Long, EntityResponse<Greeting>>> request = new GreetingsRequestBuilders(requestOptions).batchGet().ids(1L).build();
ResponseFuture<BatchKVResponse<Long, EntityResponse<Greeting>>> future = client.sendRequest(request);
Response<BatchKVResponse<Long, EntityResponse<Greeting>>> greetingResponse = future.getResponse();
checkContentEncodingHeaderIsAbsent(greetingResponse);
return greetingResponse.getEntity().getResults().get(1L).getEntity();
}
use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestAssociationsResource method testBatchGet.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testBatchGet(RestliRequestOptions requestOptions) throws RemoteInvocationException {
Request<BatchKVResponse<CompoundKey, Message>> request = new AssociationsBuilders(requestOptions).batchGet().ids(DB.keySet()).buildKV();
ResponseFuture<BatchKVResponse<CompoundKey, Message>> responseFuture = getClient().sendRequest(request);
Response<BatchKVResponse<CompoundKey, Message>> response = responseFuture.getResponse();
BatchKVResponse<CompoundKey, Message> entity = response.getEntity();
Assert.assertEquals(entity.getErrors().size(), 0);
Assert.assertEquals(entity.getResults().size(), 2);
for (CompoundKey id : DB.keySet()) {
Assert.assertTrue(entity.getResults().containsKey(id));
Assert.assertEquals(entity.getResults().get(id), DB.get(id));
}
}
use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestAssociationsResource method testBatchGetEntity.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testBatchGetEntity(RestliRequestOptions requestOptions) throws RemoteInvocationException {
Request<BatchKVResponse<CompoundKey, EntityResponse<Message>>> request = new AssociationsRequestBuilders(requestOptions).batchGet().ids(DB.keySet()).build();
ResponseFuture<BatchKVResponse<CompoundKey, EntityResponse<Message>>> responseFuture = getClient().sendRequest(request);
Response<BatchKVResponse<CompoundKey, EntityResponse<Message>>> response = responseFuture.getResponse();
BatchKVResponse<CompoundKey, EntityResponse<Message>> entityResponse = response.getEntity();
Assert.assertEquals(entityResponse.getErrors().size(), 0);
Assert.assertEquals(entityResponse.getResults().size(), 2);
for (CompoundKey id : DB.keySet()) {
EntityResponse<Message> single = entityResponse.getResults().get(id);
Assert.assertTrue(entityResponse.getResults().containsKey(id));
Assert.assertEquals(single.getEntity(), DB.get(id));
}
}
use of com.linkedin.restli.client.response.BatchKVResponse 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<Long, UpdateStatus>();
final CountDownLatch latch = new CountDownLatch(scatterGatherRequests.size());
final List<Throwable> errors = new ArrayList<Throwable>();
final List<BatchKVResponse<Long, UpdateStatus>> responses = new ArrayList<BatchKVResponse<Long, UpdateStatus>>();
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>>();
Set<Long> responseIds = new HashSet<Long>();
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);
}
use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestGreetingsClient method testNewCookbookInBatch.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testNewCookbookInBatch(RestliRequestOptions requestOptions) throws Exception {
final GreetingsRequestBuilders builders = new GreetingsRequestBuilders(requestOptions);
// GET
final BatchGetEntityRequestBuilder<Long, Greeting> batchGetBuilder = builders.batchGet();
Request<BatchKVResponse<Long, EntityResponse<Greeting>>> request = batchGetBuilder.ids(1L).build();
ResponseFuture<BatchKVResponse<Long, EntityResponse<Greeting>>> future = getClient().sendRequest(request);
Response<BatchKVResponse<Long, EntityResponse<Greeting>>> greetingResponse = future.getResponse();
// PUT
Greeting greeting = new Greeting(greetingResponse.getEntity().getResults().get(1L).getEntity().data().copy());
greeting.setMessage("This is a new message!");
Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(1L, greeting).build();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
Request<BatchKVResponse<Long, EntityResponse<Greeting>>> request2 = builders.batchGet().ids(1L).build();
ResponseFuture<BatchKVResponse<Long, EntityResponse<Greeting>>> future2 = getClient().sendRequest(request2);
greetingResponse = future2.get();
Greeting repeatedGreeting = new Greeting();
repeatedGreeting.setMessage("Hello Hello");
repeatedGreeting.setTone(Tone.SINCERE);
List<Greeting> entities = Arrays.asList(repeatedGreeting, repeatedGreeting);
Request<BatchCreateIdResponse<Long>> request3 = builders.batchCreate().inputs(entities).build();
BatchCreateIdResponse<Long> statuses = getClient().sendRequest(request3).getResponse().getEntity();
for (CreateIdStatus<Long> status : statuses.getElements()) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
@SuppressWarnings("deprecation") String id = status.getId();
Assert.assertEquals(status.getKey().longValue(), Long.parseLong(id));
Assert.assertNotNull(status.getKey());
}
}
Aggregations