Search in sources :

Example 1 with IndividualRequestMap

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);
}
Also used : IndividualRequest(com.linkedin.restli.common.multiplexer.IndividualRequest) IndividualRequestMap(com.linkedin.restli.common.multiplexer.IndividualRequestMap) MultiplexedRequestContent(com.linkedin.restli.common.multiplexer.MultiplexedRequestContent) Test(org.testng.annotations.Test)

Example 2 with IndividualRequestMap

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);
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) IndividualRequest(com.linkedin.restli.common.multiplexer.IndividualRequest) IndividualRequestMap(com.linkedin.restli.common.multiplexer.IndividualRequestMap) StringMap(com.linkedin.data.template.StringMap) IndividualBody(com.linkedin.restli.common.multiplexer.IndividualBody) MultiplexedRequestContent(com.linkedin.restli.common.multiplexer.MultiplexedRequestContent) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 3 with IndividualRequestMap

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);
}
Also used : IndividualRequestMap(com.linkedin.restli.common.multiplexer.IndividualRequestMap) IndividualRequest(com.linkedin.restli.common.multiplexer.IndividualRequest) Task(com.linkedin.parseq.Task) ArrayList(java.util.ArrayList)

Example 4 with IndividualRequestMap

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();
}
Also used : IndividualRequestMap(com.linkedin.restli.common.multiplexer.IndividualRequestMap) MultiplexedRequestContent(com.linkedin.restli.common.multiplexer.MultiplexedRequestContent)

Example 5 with IndividualRequestMap

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;
}
Also used : IndividualRequest(com.linkedin.restli.common.multiplexer.IndividualRequest) IndividualRequestMap(com.linkedin.restli.common.multiplexer.IndividualRequestMap) StringMap(com.linkedin.data.template.StringMap)

Aggregations

IndividualRequestMap (com.linkedin.restli.common.multiplexer.IndividualRequestMap)16 IndividualRequest (com.linkedin.restli.common.multiplexer.IndividualRequest)10 MultiplexedRequestContent (com.linkedin.restli.common.multiplexer.MultiplexedRequestContent)7 StringMap (com.linkedin.data.template.StringMap)5 RestResponse (com.linkedin.r2.message.rest.RestResponse)3 HashMap (java.util.HashMap)3 Test (org.testng.annotations.Test)3 Callback (com.linkedin.common.callback.Callback)2 ByteString (com.linkedin.data.ByteString)1 DataMap (com.linkedin.data.DataMap)1 Task (com.linkedin.parseq.Task)1 RestException (com.linkedin.r2.message.rest.RestException)1 TestRecord (com.linkedin.restli.client.test.TestRecord)1 EmptyRecord (com.linkedin.restli.common.EmptyRecord)1 IndividualBody (com.linkedin.restli.common.multiplexer.IndividualBody)1 IndividualResponseMap (com.linkedin.restli.common.multiplexer.IndividualResponseMap)1 HttpCookie (java.net.HttpCookie)1 ArrayList (java.util.ArrayList)1 MimeTypeParseException (javax.activation.MimeTypeParseException)1