use of com.linkedin.restli.common.multiplexer.IndividualRequestMap in project rest.li by linkedin.
the class TestMultiplexedRequestBuilder method testParallel.
@Test
public void testParallel() throws RestLiEncodingException {
MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createParallelRequest().addRequest(request1, callback1).addRequest(request2, callback2).build();
//verify requests
IndividualRequest ir1 = fakeIndividualRequest(getUri(ID1));
IndividualRequest ir2 = fakeIndividualRequest(getUri(ID2));
MultiplexedRequestContent expectedRequests = new MultiplexedRequestContent();
expectedRequests.setRequests(new IndividualRequestMap(ImmutableMap.of("0", ir1, "1", ir2)));
assertMultiplexedRequestContentEquals(multiplexedRequest.getContent(), expectedRequests);
verifyCallbacks(multiplexedRequest);
}
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 MultiplexedRequestHandlerImpl method createParallelRequestsTask.
private Task<?> createParallelRequestsTask(RestRequest envelopeRequest, RequestContext requestContext, IndividualRequestMap individualRequests, IndividualResponseMap individualResponses, Map<String, HttpCookie> responseCookies) {
List<Task<?>> tasks = new ArrayList<>(individualRequests.size());
for (IndividualRequestMap.Entry<String, IndividualRequest> individualRequestMapEntry : individualRequests.entrySet()) {
String id = individualRequestMapEntry.getKey();
IndividualRequest individualRequest = individualRequestMapEntry.getValue();
// create a task for the current request
Task<Void> individualRequestTask = createRequestHandlingTask(id, envelopeRequest, requestContext, individualRequest, individualResponses, responseCookies);
IndividualRequestMap dependentRequests = individualRequest.getDependentRequests();
if (dependentRequests.isEmpty()) {
tasks.add(individualRequestTask);
} else {
// recursively process dependent requests
Task<?> dependentRequestsTask = createParallelRequestsTask(envelopeRequest, requestContext, dependentRequests, individualResponses, responseCookies);
// tasks for dependant requests are executed after the current request's task
tasks.add(individualRequestTask.andThen(dependentRequestsTask));
}
}
return Tasks.par(tasks);
}
use of com.linkedin.restli.common.multiplexer.IndividualRequestMap in project rest.li by linkedin.
the class TestAsyncMethodInvocationPlanClass method muxRestRequest.
private RestRequest muxRestRequest(Map<String, IndividualRequest> requests) throws URISyntaxException, IOException {
MultiplexedRequestContent content = new MultiplexedRequestContent();
content.setRequests(new IndividualRequestMap(requests));
return muxRequestBuilder().setMethod(HttpMethod.POST.name()).setEntity(CODEC.mapToBytes(content.data())).setHeader(RestConstants.HEADER_CONTENT_TYPE, RestConstants.HEADER_VALUE_APPLICATION_JSON).build();
}
use of com.linkedin.restli.common.multiplexer.IndividualRequestMap in project rest.li by linkedin.
the class TestAsyncMethodInvocationPlanClass method individualRequest.
private static IndividualRequest individualRequest(String url, Map<String, String> headers, Map<String, IndividualRequest> dependentRequests) {
IndividualRequest individualRequest = new IndividualRequest();
individualRequest.setMethod(HttpMethod.GET.name());
individualRequest.setRelativeUrl(url);
if (headers != null && headers.size() > 0) {
individualRequest.setHeaders(new StringMap(headers));
}
individualRequest.setDependentRequests(new IndividualRequestMap(dependentRequests));
return individualRequest;
}
Aggregations