use of com.linkedin.restli.common.multiplexer.IndividualRequestMap in project rest.li by linkedin.
the class TestMultiplexedRequestBuilder method testBody.
@Test
public void testBody() throws IOException {
TestRecord entity = fakeEntity(0);
CreateRequest<TestRecord> request = fakeCreateRequest(entity);
NoOpCallback<EmptyRecord> callback = new NoOpCallback<EmptyRecord>();
MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createSequentialRequest().addRequest(request, callback).build();
IndividualRequest individualRequest = new IndividualRequest().setMethod(HttpMethod.POST.name()).setHeaders(new StringMap(HEADERS)).setRelativeUrl(BASE_URI).setBody(new IndividualBody(entity.data()));
MultiplexedRequestContent expectedRequests = new MultiplexedRequestContent();
expectedRequests.setRequests(new IndividualRequestMap(ImmutableMap.of("0", individualRequest)));
assertMultiplexedRequestContentEquals(multiplexedRequest.getContent(), expectedRequests);
}
use of com.linkedin.restli.common.multiplexer.IndividualRequestMap in project rest.li by linkedin.
the class MultiplexedRequestBuilder method buildParallel.
private MultiplexedRequest buildParallel() throws RestLiEncodingException {
Map<Integer, Callback<RestResponse>> callbacks = new HashMap<Integer, Callback<RestResponse>>(_requestsWithCallbacks.size());
IndividualRequestMap individualRequests = new IndividualRequestMap(_requestsWithCallbacks.size());
// Dependent requests map is always empty
IndividualRequestMap dependentRequests = new IndividualRequestMap();
for (int i = 0; i < _requestsWithCallbacks.size(); i++) {
RequestWithCallback<?> requestWithCallback = _requestsWithCallbacks.get(i);
IndividualRequest individualRequest = toIndividualRequest(requestWithCallback.getRequest(), dependentRequests);
individualRequests.put(Integer.toString(i), individualRequest);
callbacks.put(i, wrapCallback(requestWithCallback));
}
return toMultiplexedRequest(individualRequests, callbacks);
}
use of com.linkedin.restli.common.multiplexer.IndividualRequestMap in project rest.li by linkedin.
the class MultiplexedRequestBuilder method buildSequential.
private MultiplexedRequest buildSequential() throws RestLiEncodingException {
Map<Integer, Callback<RestResponse>> callbacks = new HashMap<Integer, Callback<RestResponse>>(_requestsWithCallbacks.size());
// Dependent requests - requests which are dependent on the current request (executed after the current request)
IndividualRequestMap dependentRequests = new IndividualRequestMap();
// We start with the last request in the list and proceed backwards because sequential ordering is built using reverse dependencies
for (int i = _requestsWithCallbacks.size() - 1; i >= 0; i--) {
RequestWithCallback<?> requestWithCallback = _requestsWithCallbacks.get(i);
IndividualRequest individualRequest = toIndividualRequest(requestWithCallback.getRequest(), dependentRequests);
dependentRequests = new IndividualRequestMap();
dependentRequests.put(Integer.toString(i), individualRequest);
callbacks.put(i, wrapCallback(requestWithCallback));
}
return toMultiplexedRequest(dependentRequests, callbacks);
}
use of com.linkedin.restli.common.multiplexer.IndividualRequestMap in project rest.li by linkedin.
the class MultiplexerTestBase method fakeIndividualRequest.
protected static IndividualRequest fakeIndividualRequest(String url, Map<String, IndividualRequest> dependentCalls) {
IndividualRequest request = new IndividualRequest();
request.setMethod(HttpMethod.GET.name());
request.setHeaders(new StringMap(HEADERS));
request.setRelativeUrl(url);
request.setDependentRequests(new IndividualRequestMap(dependentCalls));
return request;
}
use of com.linkedin.restli.common.multiplexer.IndividualRequestMap in project rest.li by linkedin.
the class MultiplexerTestBase method assertMultiplexedRequestContentEquals.
protected static void assertMultiplexedRequestContentEquals(MultiplexedRequestContent actual, MultiplexedRequestContent expected) {
IndividualRequestMap actualRequests = actual.getRequests();
IndividualRequestMap expectedRequests = expected.getRequests();
Assert.assertEquals(actualRequests.size(), expectedRequests.size());
for (String id : expectedRequests.keySet()) {
assertIndividualRequestEquals(actualRequests.get(id), expectedRequests.get(id));
}
}
Aggregations