Search in sources :

Example 6 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 7 with IndividualRequestMap

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);
}
Also used : IndividualRequestMap(com.linkedin.restli.common.multiplexer.IndividualRequestMap) IndividualRequest(com.linkedin.restli.common.multiplexer.IndividualRequest) Callback(com.linkedin.common.callback.Callback) HashMap(java.util.HashMap) RestResponse(com.linkedin.r2.message.rest.RestResponse)

Example 8 with IndividualRequestMap

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);
}
Also used : IndividualRequestMap(com.linkedin.restli.common.multiplexer.IndividualRequestMap) IndividualRequest(com.linkedin.restli.common.multiplexer.IndividualRequest) Callback(com.linkedin.common.callback.Callback) HashMap(java.util.HashMap) RestResponse(com.linkedin.r2.message.rest.RestResponse)

Example 9 with IndividualRequestMap

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

Example 10 with IndividualRequestMap

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

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