use of com.linkedin.restli.common.EntityResponse in project parseq by linkedin.
the class GetRequestGroup method unbatchResponse.
private static <K, RT extends RecordTemplate> Response<RT> unbatchResponse(BatchGetEntityRequest<K, RT> request, Response<BatchKVResponse<K, EntityResponse<RT>>> batchResponse, Object id) throws RemoteInvocationException {
final BatchKVResponse<K, EntityResponse<RT>> batchEntity = batchResponse.getEntity();
final ErrorResponse errorResponse = batchEntity.getErrors().get(id);
if (errorResponse != null) {
throw new RestLiResponseException(errorResponse);
}
final EntityResponse<RT> entityResponse = batchEntity.getResults().get(id);
if (entityResponse != null) {
final RT entityResult = entityResponse.getEntity();
if (entityResult != null) {
return new ResponseImpl<>(batchResponse, entityResult);
}
}
LOGGER.debug("No result or error for base URI : {}, id: {}. Verify that the batchGet endpoint returns response keys that match batchGet request IDs.", request.getBaseUriTemplate(), id);
throw NOT_FOUND_EXCEPTION;
}
use of com.linkedin.restli.common.EntityResponse in project rest.li by linkedin.
the class TestBatchEntityResponseDecoder method testDecoding.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchEntityResponseDataProvider")
public void testDecoding(List<String> keys, ProtocolVersion protocolVersion) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, IOException {
final String resultKey = keys.get(0);
final String statusKey = keys.get(1);
final String errorKey = keys.get(2);
final DataMap resultData = new DataMap();
resultData.put(resultKey, _record.data());
final DataMap statusData = new DataMap();
statusData.put(statusKey, _status.getCode());
final DataMap errorData = new DataMap();
errorData.put(errorKey, _error.data());
final DataMap data = new DataMap();
data.put(BatchResponse.RESULTS, resultData);
data.put(BatchResponse.STATUSES, statusData);
data.put(BatchResponse.ERRORS, errorData);
final BatchEntityResponseDecoder<String, TestRecord> decoder = new BatchEntityResponseDecoder<>(new TypeSpec<>(TestRecord.class), new TypeSpec<>(String.class), Collections.<String, CompoundKey.TypeInfo>emptyMap(), null);
final BatchKVResponse<String, EntityResponse<TestRecord>> response = decoder.wrapResponse(data, Collections.<String, String>emptyMap(), protocolVersion);
final Map<String, EntityResponse<TestRecord>> results = response.getResults();
final Map<String, ErrorResponse> errors = response.getErrors();
final Collection<String> uniqueKeys = new HashSet<>(keys);
Assert.assertEquals(results.size(), uniqueKeys.size());
Assert.assertEquals(errors.size(), 1);
Assert.assertEquals(results.get(resultKey).getEntity(), _record);
Assert.assertEquals(results.get(statusKey).getStatus(), _status);
Assert.assertEquals(results.get(errorKey).getError(), _error);
Assert.assertEquals(errors.get(errorKey), _error);
// Check that the response still contains the original data map
Assert.assertEquals(response.data(), data);
}
use of com.linkedin.restli.common.EntityResponse in project rest.li by linkedin.
the class TestScatterGather method testBuildSGGetEntityRequests.
private static void testBuildSGGetEntityRequests(int numEndpoints, ScatterGatherBuilder<Greeting> sg, Long[] ids) throws ServiceUnavailableException {
Collection<ScatterGatherBuilder.KVRequestInfo<Long, EntityResponse<Greeting>>> requests = buildScatterGatherGetEntityRequests(sg, ids);
Assert.assertEquals(requests.size(), numEndpoints);
Set<Set<String>> requestIdSets = new HashSet<>();
Set<Long> requestIds = new HashSet<>();
for (ScatterGatherBuilder.KVRequestInfo<Long, EntityResponse<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<BatchKVResponse<Long, EntityResponse<Greeting>>> request = requestInfo.getRequest();
Set<String> expectedParams = new HashSet<>();
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);
}
use of com.linkedin.restli.common.EntityResponse in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testBatchGetRequestWithPartialErrors.
@Test
public void testBatchGetRequestWithPartialErrors() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Set<Long> ids = Sets.newHashSet(Arrays.asList(-1L, -2L, 1L, 2L, 3L));
CompletionStage<Map<Long, EntityResponse<Greeting>>> result = greetings.batchGet(ids);
CompletableFuture<Map<Long, EntityResponse<Greeting>>> future = result.toCompletableFuture();
Map<Long, EntityResponse<Greeting>> resultMap = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(resultMap.size(), ids.size());
for (Long id : ids) {
EntityResponse<Greeting> g = resultMap.get(id);
Assert.assertNotNull(g);
if (id > 0) {
Assert.assertTrue(g.hasEntry());
Assert.assertEquals(id, g.getEntity().getId());
} else {
Assert.assertTrue(g.hasError());
}
}
}
use of com.linkedin.restli.common.EntityResponse in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testBatchGetRequest.
@Test
public void testBatchGetRequest() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Set<Long> ids = Sets.newHashSet(Arrays.asList(1L, 2L, 3L));
CompletionStage<Map<Long, EntityResponse<Greeting>>> result = greetings.batchGet(ids);
CompletableFuture<Map<Long, EntityResponse<Greeting>>> future = result.toCompletableFuture();
Map<Long, EntityResponse<Greeting>> resultMap = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(resultMap.size(), ids.size());
for (Long id : ids) {
EntityResponse<Greeting> g = resultMap.get(id);
Assert.assertNotNull(g);
Assert.assertTrue(g.hasEntry());
Assert.assertEquals(id, g.getEntity().getId());
}
}
Aggregations